Benchmarks creation of new errors. Current expected range is ~0.1-0.2ms to create errors from 100 go routines simultaneously. This is fairly close to just spinning up go routines and putting stuff on channels and doing some very simple work, thus error creation should be cheap enough for all most al
(b *testing.B)
| 337 | // and putting stuff on channels and doing some very simple work, thus |
| 338 | // error creation should be cheap enough for all most all use cases. |
| 339 | func BenchmarkNew(b *testing.B) { |
| 340 | a := func() error { |
| 341 | b := func() error { |
| 342 | c := func() error { |
| 343 | return New("Hello world, grab me a stack trace!") |
| 344 | } |
| 345 | return c() |
| 346 | } |
| 347 | return b() |
| 348 | } |
| 349 | nRoutines := 100 |
| 350 | errChan := make(chan error, nRoutines) |
| 351 | b.ResetTimer() |
| 352 | for i := 0; i < b.N; i++ { |
| 353 | for k := 0; k < nRoutines; k++ { |
| 354 | go func() { |
| 355 | err := a() |
| 356 | errChan <- err |
| 357 | }() |
| 358 | } |
| 359 | for k := 0; k < nRoutines; k++ { |
| 360 | <-errChan |
| 361 | } |
| 362 | } |
| 363 | } |