C++ Benchmarking tips? (mostly Linux)

I'm working on (CPU) benchmarking software. Mostly for Linux. The benchmarking is written in pure C++, the interface will be written in either Qt4 (C++) or Glype.

But I need some tips for the benchmarking. Right now, i've only got two CPU tests:

- A speed/torture test, by calculating prime numbers on a non-efficient way.

- A 'real world' test, by calculating prime numbers on a very efficient way.

Does anyone have any tips for creating benchmark tests with C++?

 

I am not really an expert at making benchmarks (never made any, unless you class badly written software as one :P) but you could try and create a benchmark based around how many hashes a computer can generate using a memory intensive hash.

the last torture test i wrote was for gpu's but it will work for a cpu as well. basicaly calculate 'e' to a very very persise number

1+ (1/1) +(1/(1+2)) + (1/(1+2+3))+...

its a great way to test overall performance. now, in reality you will only be as persise as your sizeof(long double) but you know... its a benchmark so it doesnt matter too much.

you can do the above with recursion or two nested loops. so its fairly easy.

 

 

if you want a fairly inifficent way of finding primes:

 

for(float prime = 0; prime < MAX_PRIME; prime++){

   for(int check = prime; check < prime/2; check++){

      if(prime % check == 0){

          std::cerr<"holy shit batman, this number ant' a prime! \n";

          break;

  }}}

 

god i hate that bracket format, but code tags dont work

Well calculating primes is always the classic thing to do.

I've thought of a more interesting approach though. You could use Conway's Game of Life as a way of utilising the CPU, and see how far you can get with a particular pattern in a specified time period. Or you could test how long it would take to get to a certain frame in the pattern.

Make sure the program uses multiple threads, you really need each core to be at 100%. Which is not something a blank project would do automatically.

Thanks, thats a good idea to start with.

And yes, I know how to use multipile threads. :D

Right now I use 'sysconf(_SC_NPROCESSORS_ONLN)' to determinate how many cores/threads there are.

ooh, another easy one to program, but can be very intensive. compulte the collatz conjecture.

or, you can compute how many itterations of randomness it takes to get a n length pattern. just generate a random number, bounded by a and b. then concatonate it to the rest of them, do this _length ammount of times, then search for the string. you could find out how long it takes to randomly generate shakespear!

have you looked into the boost libraries? their threading classes are very nice. have not tried the new c standards method... but i can vouch for boost.