Why benchmark?

Multimedia processing is usually quite computationally intensive, and faster-than-realtime processing is a often a requirement. Small systems, such as smart phones, increase the importance of minimizing CPU and memory use.

Every time the code is changed benchmarking is advised.

In order to benchmark a change, the simplest approach is to run the code and see if it is faster than before, but most changes will not have a big enough impact on performance that you can see it just by looking at the code run, so you will need to use a profiling or tracing tool. Ideally you should run your test several times, collect the resulting time and compute the average and standard deviation. This reduces any little variations in CPU load or memory access times that are unrelated to your code - for instance, due to whatever else the system happens to also be running at the same time.

Benchmarking tools

OProfile (Linux)

OProfile is a system profiler for Linux. It had been superceeded for most common usages by Perf.

Perf (Linux)

Perf is Linux-only, like OProfile. Perf is simpler to use than OProfile and the reports are generally easier to understand. more

DTrace (Unix)

DTrace is a comprehensive tracing framework. It originated on Solaris, and ports to other platforms vary in maturity.

FreeBSD

DTrace port is available out of box on FreeBSD.

Linux

There is an ongoing effort to have DTrace on Linux.

MacOSX

DTrace is provided and XCode sports a simplified GUI called Instruments.

Valgrind (Unix)

Valgrind can be used to get cache profiles and calltraces, in addition to its better-known use detecting misuses of memory.

PmcTools (FreeBSD)

PmcTools aim to be a BSD equivalent of Linux Perf.

Built-in microbenchmarks

Timers

Use START_TIMER and STOP_TIMER from libavutil/timer.h

They are macro and they should not be nested; you get the number of ticks spent between the section. Compile as usual, but don't leave them in production code.

You can also git stash the changes so that you can quickly apply them when you rebase.

Hint: lower numbers are better.

avconv

The benchmark option provides the runtime and the memory usage.

avconv -nostats -v quiet -threads 1 -benchmark -i sample -f null -

CategoryWIP CategoryHowTo