我在对 Go 程序进行基准测试时遇到了问题,在我看来这就像一个 Go bug。请帮助我理解为什么不是。
简而言之:当我调用时,b.StopTimer()即使我随后调用,基准测试也会挂起b.StartTimer()。AFAICT 我正在按预期使用这些功能。
这是在 Mac OSX 10.11.5“El Capitan”上,带有go version go1.6.1 darwin/amd64; 其他一切似乎都很好。今天晚些时候我将尝试在 Linux 上检查这一点并更新问题。
这是代码。像往常一样运行go test -bench=.。
package bmtimer
import (
"testing"
"time"
)
// These appear to not matter; they can be very short.
var COSTLY_PREP_DELAY = time.Nanosecond
var RESET_STATE_DELAY = time.Nanosecond
// This however -- the measured function delay -- must not be too short.
// The shorter it is, the more iterations will be timed. …Run Code Online (Sandbox Code Playgroud) go ×1