How to Track Build Time with Bencher
Bencher supports the most popular benchmarking harnesses out-of-the-box.
Sometimes though, you want to measure how long it takes to build your deliverables themselves,
such as the compile time of an executable.
Lucky for you, Bencher also supports tracking build times.
The easiest way to track build times is to use the
bencher run
CLI subcommand
with the --build-time
flag.
Under the hood, bencher run
outputs the results as Bencher Metric Format (BMF) JSON.
It is therefore good practice to explicitly use the json
adapter.
If you had a script located at ./my_build_script.sh
that built your binary,
then you could track the build time of this binary with
bencher run
and the json
adapter.
The --build-time
flag requires a benchmark command.
The generated BMF JSON would look like this,
if your build script took 87.0
seconds to complete:
Note that the Benchmark name is /bin/sh -c ./my_build_script.sh
.
This is because our command is only a single argument, so
bencher run
defaults to the shell form for execution.
Alternatively, if you would like to force the use of the exec form,
you can either provide multiple arguments or use the --exec
flag.
If this exec form build took 86.98
seconds,
then the generated BMF JSON would look like this:
Now, the Benchmark name is simply ./my_build_script.sh
.
The ./my_build_script.sh
object contains the build-time
key.
build-time
is the slug for the built-in Build Time Measure.
The Build Time Measure is not created by default for all Projects.
However, when you use the Build Time Measure,
it will be automatically created for your Project.
The Build Time Measure object contains a Metric
with the build time value
in seconds, 87.0
and 86.98
in our examples.
The Build Time will always be rounded to the nearest two decimal places.
That is, it will never be a long decimal like 42.666666
.
Track File Size
You may want to track the file size of your deliverables,
in addition to tracking how long it takes to build them.
bencher run
supports tracking both build times and file sizes.
If the output of your ./my_build_script.sh
build script
was a binary at the path ./path/to/my_binary
,
then you could track both the compile time and the binary size with this command:
If my_binary
had a size of 42
bytes,
the generated BMF JSON would look like this:
🐰 Congrats! You have learned how to track your build time! 🎉