5

Recently, I was looking at the performance impact of tools such as strace. For instance, this blog post uses the default metrics given by dd.

I wanted to do some measurements myself but with other programs. Is there a tool that measures the speed of execution of an arbitrary program?

  • 2
    The very first step is to precisely specify what exactly you mean by "performance". E.g. are you talking about throughput, latency, jitter, something else? Cold-start, warm-start or steady-state? After you have decided what exactly you want to measure, you have to create a benchmark. Note that creating benchmarks that actually reliably measure what you want them to measure is very hard. Even benchmarking engineers that do nothing but writing benchmarks all day frequently get it wrong. (A famous example is SpecJVM98_209_db which is supposed to test database performance but actually spends … – Jörg W Mittag Oct 22 '17 at 6:13
  • 1
    … 80% of its execution time sorting strings, and thus tests the performance of the String class.) Then, when you have benchmark that reliably, repeatedly measures what you want to measure, you have to ensure that there are no environmental influences on the thing you are measuring. E.g. make sure there are no other processes running in your system that may impact the measurement, make sure that your CPU is in the same performance profile, and so on. Lastly, after you have collected your results, you need to process them with the appropriate statistical tools. – Jörg W Mittag Oct 22 '17 at 6:16
5

Read also time(7) (assuming a Linux system). You can not only use time(1) but also some time functions (e.g. clock(3), clock_gettime(2), etc...) inside the program.

See also this.

Look also into gprof(1), perf(1), oprofile(1). You may want to invoke the GCC compiler specifically (e.g. gcc -pg for gprof) for profiling and/or benchmarking, which has some overhead.

  • 1
    Specifically on Linux, perf stat -d ./a.out will print some interesting performance counters (CPU microseconds, wall-clock microseconds, branch misses, cache misses, TLB misses, and core clock cycles (not the same thing as RDTSC / wall-clock time because of turbo / frequency scaling). There's also a "record" mode to associate counts with instructions, but stat is good for microbenchmarks (whole program = one loop). ocperf.py is a nice wrapper for perf which adds symbolic names for counters like uops_issued.any. – Peter Cordes Oct 22 '17 at 1:19
4

The time command will measure the runtime of a given program.

http://man7.org/linux/man-pages/man1/time.1.html

  • 1
    Your answer helped me find the following question. It seems that time is good. However, it seems that perf stat might be better – aedcv Oct 21 '17 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.