Search code examples
c++cpubenchmarkingmulticore

How to create a simple cpu benchmark?


For a school project, which is highly relevant for our A-Levels, we want to overclock a Raspberry Pi's CPU and evaluate the performance of the CPU, prior to and post overclocking it, with a self-written benchmark.

This benchmark should be as simple as possible as it only repesents a smaller part of our presentation.

We thought it might be a good idea to use c++ as the language since it uses less resources(?). For the benchmark itself we thought about using somthing like an algorithm that calculates Pi or prime numbers to a specific point and see how long it takes.

How can we use multiple cores/a single core?

Are there a better/simpler alternatives to our thoughts?

Thanks in advance.


Solution

  • A benchmark can be as trivial as you want. If you just want something that will scale linearly with clock speed, the following is a simple micro-benchmark:

    for(uint64_t i = 0; i< MAX_COUNT ; i++) {}
    

    It only means anything in a relative sense, or if you look at the compiler generated asm.

    You have to avoid having it optimize away to nothing, e.g. compile with gcc -O1 or lower.

    Example

    You can run multiple instances of a single-threaded executable, e.g. in bash:

    for i in {1..4};do ./benchmark & done
    

    to start 4 background jobs.

    – Answer by Peter Cordes.