Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
testing: tiny benchmark with StopTimer runs forever #27217
From at least Go 1,4 onward,
If we run a tiny benchmark (count++) and use StopTimer() for initialization (count = 0) then the benchmark runs for a very long time, perhaps forever.
If we comment out StopTimer() (//b.StopTimer()) then the benchmark quickly runs to completion.
changed the title from
testing: tiny benchmarks with StopTimer run forever
testing: tiny benchmark with StopTimer runs forever
Aug 25, 2018
runtime.ReadMemStats which is called by both StartTimer and StopTimer is known to be slow, though I'm not sure it's expected to be as slow as shown here.
Calling just StartTimer without StopTimer is a noop because b.timerOn is true.
The uses of StartTimer/StopTimer are usually around one time setup/teardown code that happens before or after the b.N loop.