O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Besides the pure test support, the testing package also provides the mechanisms for measuring the code performance. For this purpose, the B struct pointer as the argument is used, and the benchmarking functions in the test file are named as BenchmarkXXXX

The essential part of the benchmark function is the manipulation with the timer and usage of the loop iteration counter N.

As you can see, the timer is manipulated with the methods, Reset/Start/StopTimer. By these, the result of the benchmark is influenced. Note that the timer starts running with the beginning of the benchmark function and the ResetTimer function just restarts it.

The N field of B is the iteration count within the measurement loop. The N value is set to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required