0

I have written a simple code in ANSI C and now would want to perform some measurements.

I have measured execution time (using clock() function under the Windows OS and clock_gettime() under the Linux OS).

Now I would want to calculate, how many IPSes (Instructions Per Second) my CPU executes, while running this code of mine. (Yes, I know that MIPS is a pathetic parameter, but even this, I want to calculate it)

It would be also nice to see, how many CPIs (Cycles Per Instruction) it takes to perform e.g. addition of 3 elements and others operations I perform. Google says how to calculate number of MIPS using calculator, some knowledge about my CPU (its clock speed), simple math and a bunch of other parameters (like CPI), but doesn't say HOW to obtain those!

I haven't found also any C/C++ function which would return the number of clock cycles needed to perform e.g. access to a local variable. There is also a problem to find a Reference Manual by Intel/AMD for a modern CPU, which would have information about opcodes and others.

I have manually calculated, that my ANSI C code takes 37 operations, but those are ANSI C operations, not CPU instructions.

Mysticial
  • 464,885
  • 45
  • 335
  • 332
  • 3
    Have you looked at the "Related"-list on the right? – Sebastian Mach Apr 10 '12 at 15:40
  • @phresnel - a lot of those are for the MIPS processor, which sine the OP mentions Windows I assume they aren't using. Gzegorz - you might want to remove the MIPS tag – Martin Beckett Apr 10 '12 at 17:35
  • 1
    The reason that those things aren't listed anywhere is because they're variable. The "number of clock cycles required to access a local variable" is somewhere between 0.3 nanoseconds, and 15 seconds, and change without warning. – Mooing Duck Apr 10 '12 at 17:56

1 Answers1

0

The easiest way of getting high accuracy timing on windows is PerformanceCounter, see How to use QueryPerformanceCounter?
Then you simply need some functions that perform the operations you are interested in timing. You have to be a little careful of caching etc. so run the calculation several times and look at the distribution of times

Community
  • 1
  • 1
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263