I’m trying to use Go package “time” to benchmark a function in my program. Been searching around, and people seem to use time.NanoSeconds() – but I think this function is no longer in the time package?
What I need is an easy way to start and stop a timer, and print out the value.
Use the existing functionality of the testing package inside your *_test.go:
and invoke
go test -bench RE(RE is a regexp to select the benches, likeBas it means*B*) typically inside the package/tool directoryOr explicitly from any place in your code – use the Benchmark function.