The Benchmark module allows you to write easily benchmarks framework to a project for timing critical parts and detecting slow parts of code.
In addition it automatically creates data files of these benchmarks, as well as a gnuplot file which can display the comparison curves of the benchmarks.
To create a basic benchmark, you have to follow these steps:
Here is a basic example of benchmark which creates two functions that will be run. These functions just print a message.
As "test", "run" are passed to eina_benchmark_new() and as the tests "work-1" and "work-2" are registered, the data files bench_test_run.work-1.data and bench_test_run.work-2.data will be created after the eina_benchmark_run() call. They contain four columns. The file bench_test_run.work-1.data contains for example:
The first column (specimen) is the integer passed to the work1() function when the test is run. The second column (experiment time) is the time, in nanosecond, that work1() takes. The third and fourth columns are self-explicit.
You can see that the integer passed work1() starts from 200 and finishes at 290, with a step of 10. These values are computed withe last 3 values passed to eina_benchmark_register(). See the document of that function for the detailed behavior.
The gnuplot file will be named bench_test_run.gnuplot. Just run:
To create the graphic of the comparison curves. The image file is named output_test_run.png.
In this section, several test will be created and run. The idea is exactly the same than in the previous section, but with some basic automatic way to run all the benchmarks. The following code benchmarks some Eina converts functions, and some Eina containers types:
gnuplot can be used to see how are performed the convert functions together, as well as how are performed the containers. So it is now easy to see that the hexadecimal convert function is faster than the decimal one, and that arrays are faster than lists.
You can improve all that by executing automatically gnuplot in your program, or integrate the Eina benchmark framework in an autotooled project. See that page for more information.