Getting an accurate execution time in C++ (micro seconds)

If you are using c++11 or later you could use std::chrono::high_resolution_clock. A simple use case : auto start = std::chrono::high_resolution_clock::now(); … auto elapsed = std::chrono::high_resolution_clock::now() – start; long long microseconds = std::chrono::duration_cast<std::chrono::microseconds>( elapsed).count(); This solution has the advantage of being portable. Beware that micro-benchmarking is hard. It’s very easy to measure the wrong thing (like … Read more

What is FLOP/s and is it a good measure of performance?

It’s a pretty decent measure of performance, as long as you understand exactly what it measures. FLOPS is, as the name implies FLoating point OPerations per Second, exactly what constitutes a FLOP might vary by CPU. (Some CPU’s can perform addition and multiplication as one operation, others can’t, for example). That means that as a … Read more

Is the UNIX `time` command accurate enough for benchmarks? [closed]

time produces good enough times for benchmarks that run over one second otherwise the time it took exec()ing a process may be large compared to its run-time. However, when benchmarking you should watch out for context switching. That is, another process may be using CPU thus contending for CPU with your benchmark and increasing its … Read more

Java vs C#: Are there any studies that compare their execution speed?

The best comparison that I am aware of is The Computer Language Benchmarks Game. It compares speed, memory use and source code size for (currently) 10 benchmarks across a large number of programming languages. The implementations of the benchmarks are user-submitted and there are continuous improvements, so the standings shift around somewhat. The comparison is … Read more

Mystifying microbenchmark result for stream API on Java 12 vs. Java 8 with -gc true

Thanks, everyone for the help and especially to @Aleksey Shipilev! After applied changes to JMH benchmark, the results look more realistic (?) Changes: Change the setup method to be executed before/after each iteration of the benchmark. @Setup(Level.Invocation) -> @Setup(Level.Iteration) Stop JMH forcing GC between iterations. Forcing Full GC before each iteration is quite likely to … Read more