MCPcopy Index your code
hub / github.com/dropbox/godropbox / BenchmarkNew

Function BenchmarkNew

errors/errors_test.go:339–363  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
339func 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}

Callers

nothing calls this directly

Calls 1

NewFunction · 0.70

Tested by

no test coverage detected