How can you test how many instructions per second your computer can do?

algorithm, benchmarking, c, c++, sorting

Solution

If you want to know what your CPU can do, then look at the documentation. Your CPU vendor specifies the latency and throughput of all instructions, as well as a variety of other information (how many instructions can be issued or retired per cycle, cache latencies and much more). Based on this, you can compute the theoretical peak throughput.

If you want to do what your CPU is actually doing then run your own code and measure its performance.

However, keep in mind that modern CPUs are really complex beasts, and their performance depends on a wide variety of factors, and you will very rarely be able to come anywhere near maxing out your CPU, and understanding why, or what exactly is holding your code back requires a fairly thorough understanding of the hardware. (My usual rule of thumb is that you're doing very good if you get a sustained 30-40% of the theoretical peak FLOPS)

Problem

Is there a quick/easy way to do this (for at least a rough estimate) ? I'm benchmarking algorithms and I thought it would be cool to know the absolute speed at which my computer is executing instructions and compare that with my asymptotic analysis.

Original source

Related problems