$darkmode
Elektra 0.11.0
|
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:
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:
and save it in the folder benchmarks/data
:
. As you can see the filename has to use the pattern:
, where $plugin
specifies the name of the plugin the benchmark tool should call. We can now call the get
method of the plugin YAML CPP using the following shell command
. If you can want you can also use the time
utility to measure the execution time of the last command:
. As you can see in the output above a real configuration file that tests the performance of the YAML CPP plugin should be much larger.
Now that you know how to execute benchmark_plugingetset
, you can use it to compare the performance of different plugins. Since you usually want
benchmark_plugingetset
multiple times, andit makes sense to use a benchmarking tool such as hyperfine for that task. For our tutorial we assume that you copied the file keyframes.yaml
to the locations
benchmarks/data/test.yamlcpp.in
, andbenchmarks/data/test.yanlr.in
. You can do that using the following commands:
. Afterwards you can use:
to compare the performance of the plugins. The output of this benchmark would look something like this:
. You can now remove the input files and the folder benchmarks/data
: