I wrote a test for my chess engine in Go:
func BenchmarkStartpos(b *testing.B) {
board := ParseFen(startpos)
for i := 0; i < b.N; i++ {
Perft(&board, 5)
}
}
I see this output when it starts:
goos: darwin
goarch: amd64
BenchmarkStartpos-4 10 108737398 ns/op
PASS
ok _/Users/dylhunn/Documents/go-chess 1.215s
I want to use the runtime (in this case 108737398 ns/op) to calculate another value, and also print it as a result of the test. In particular, I want to output nodes per second, which are given as a result of the call Perftdivided by the time by the call.
How do I access the test run time so that I can print my own results?
source
share