As part of a college project, I need to compare the speed of arithmetic operations directly in binary on different processors.

Example: At what speed will binary addition be performed on an Intel Core I5-12400 processor?

Initially, I had the idea to write a program myself that would perform the appropriate tests. The problem is that I'm programming in python so the final results wouldn't be accurate. I don't have time to learn another language.

I was looking for ready-made solutions in the form of programs or repositories on the Internet. I also looked for ready-made final data in various scientific papers.

I have a question for the community here. Do you know any ready-made programs, repositories or scientific papers that will allow me to obtain the data needed to prepare the study?

Thank you very much for your help on behalf of myself and the rest of my group.

  • $\begingroup$ How accurate do your results need to be? If you just want to compare the speed of different CPUs overall - gamers have already done this for us and many comparison sites exist - for example cpu-benchmark.org (no relation). I was going to suggest comparing GFLOPS but it seems that GFLOPS numbers abound only for GPUs, not CPUs. $\endgroup$
    – user253751
    Nov 16, 2022 at 13:57

4 Answers 4


You don't really need to learn an entire new language.

Here's a 1-line program in C (running on Linux):

$ cat test.c
int main() { register long i; for (i=-10L*1000*1000*1000; i<0; ++i); }

$ gcc test.c

$ time ./a.out
real    0m5.064s
user    0m5.056s
sys     0m0.008s

It took 5 seconds to perform 10 billion iterations.

Isolating how much of that was spent on the addition itself won't be as easy.

But we can look at the assembler that was generated by the compiler:

$ gcc -S test.c

$ more test.s
        jmp         .L2
        addq        $1, %rbx
        testq       %rbx, %rbx
        js         .L3

The loop consisted of an addition, a comparison, and a jump.

You'd have to look at the manufacturer's specs for how many clock cycles are required for each of the three operations. Knowing that, you can assign the appropriate fraction to the addition.

Of course there are other factors to consider too.
In this case "addition" means adding 1 to i, but perhaps the timing would be different if it added the value of j instead of 1. As asked, the question doesn't specify exactly what is meant by "arithmetic operations directly".

  • $\begingroup$ Remember that C++ compilers are completely insane. For example, if you add optimization flags to gcc, then you get a single instruction. $\endgroup$
    – Pål GD
    Nov 16, 2022 at 12:10
  • $\begingroup$ I had a loop like that taking 3/8ths of a cycle per iteration. Investigation showed that it unrolled the empty loop 8 times, so instead of 10 billion times doing nothing it did 1.25 billion iterations doing nothing. $\endgroup$
    – gnasher729
    Nov 16, 2022 at 18:19

There are two possibilities: Either you write code in a language where you can see the assembler instructions that are produced. Or you go through processor manuals and figure it out.

Now on basically every processor one addition, subtraction, and, or, xor operation will be performed in one cycle - the result is available one cycle after the operands were available.

What that doesn't tell you is how long say 100 operations take. Newer processors can usually perform more than one operation at the same time - as long as one operation doesn't depend on the results of the previous one. And you usually have vector operations that can do two, four, eight or more integer operations at one time, in one cycle. And you have processors with multiple cores. A processor with eight cores can do eight times as many operations.

To measure that, you really have to write code.

And according to computer scientists, an addition of two n-bit numbers takes O (log n) time with a good implementation :-)


"Speed" does not have a well-defined meaning at that level. Basic CPU instructions have a latency (or in general, more than one) and a throughput. Different ways of measuring the "speed" could result in either the latency or the throughput or, if not done carefully, neither. Arbitrarily executing instructions without designing a specific experiment will give some answer, but may not yield useful information with a clear interpretation.

Multiple latencies can occur because the latency from one input of an instruction to the output may be different from the latency from another input to the output, for example a complex multi-µop instruction may perform some operations on one input first and only read the second input later. Addition is not that complex though.

The latencies and throughputs of many x86 instructions on a variety of x86 processors have been determined with a methodology described in uops.info: Characterizing Latency, Throughput, and Port Usage of Instructions on Intel Microarchitectures, with the data available at https://uops.info/index.html

Your processor, the Intel® Core™ i5-12400, is an Alder Lake. It has two different types of cores, P-cores and E-cores. Instruction latencies and throughputs are different on the different types of core.

There are similar lists available for, for example, Apple M1

  • $\begingroup$ And measuring speed on different cores can be very difficult because you can’t really control which core is used. $\endgroup$
    – gnasher729
    Nov 16, 2022 at 18:22

In modern computers, the time for an operation cannot be measured, full stop. Because it is highly non-deterministic.

The running time depends on important factors such as memory response time (across several levels of cache plus virtual memory), as well as (hyperthreaded) pipeline utilization. In addition, for the heaviest operations, time can depend on the values of the operands. Last but not least, you will be timing a loop at the same time.

So any empirical measurement will not necessarily reflect the behavior in real use.

The best that you can do is to refer to the manufacturers' timing tables.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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