Elektra  0.9.3
Benchmarking

One of the usual questions for a standard benchmark is, how much more or less time two or more different programs take to execute on the same hardware. This tutorial will introduce some tools and techniques that will help you to answer this question. For that purpose we compare the time it takes for certain YAML storage plugins to translate YAML data into Elektra’s key set structure. Most of the techniques we describe here should be applicable too, if you want to compare the run-time of other parts of Elektra. If you want to know why a certain part of Elektra takes a long time to execute, then you might also be interested in the profiling tutorial.

If you have never translated the code base of Elektra before, then please take a look here before you continue.

Usually you want to compare the execution time of the fastest version of a compiled binary. For that purpose it makes sense to change the CMake build type to Release, which means that the generated build system will optimize the code and strip debug symbols. You should also disable the logger and debug code. An example CMake command that uses Ninja as build tool could look like this:

mkdir build
cd build
cmake -GNinja .. \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_LOGGER=OFF \
-DENABLE_DEBUG=OFF \
-DPLUGINS=ALL
ninja
cd .. # Change working directory back to the root of repository

Elektra already includes a tool that helps you to benchmark the get and set methods of a certain plugin called `benchmark_plugingetset`. To show you how to use benchmark_plugingetset, we create a file named test.yamlcpp.in with the following content:

- You,
- Me, &
- The Violence

and save it in the folder benchmarks/data:

mkdir -p benchmarks/data
printf -- '- You,\n' > benchmarks/data/test.yamlcpp.in
printf -- '- Me, &\n' >> benchmarks/data/test.yamlcpp.in
printf -- '- The Violence' >> benchmarks/data/test.yamlcpp.in

. As you can see the filename has to use the pattern:

test.$plugin.in

, where $plugin specifies the name of the plugin the benchmark tool should call. We can now call the get method of the plugin ../../src/plugins/yamlcpp/README.md "YAML CPP" using the following shell command

``` build/bin/benchmark_plugingetset benchmarks/data user yamlcpp get

↑ ↑ ↑ ↑

parent directory namespace plugin only use `get`

# of config file plugin method

. If you can want you can also use the `time` utility to measure the execution time of the last command:

time build/bin/benchmark_plugingetset benchmarks/data user yamlcpp get #> 0.00 real 0.00 user 0.00 sys ```

. As you can see in the output above a real configuration file that tests the performance of the ../../src/plugins/yamlcpp/README.md "YAML CPP" plugin should be much larger.