I've been tasked to generate a benchmark program that estimates the MIPS of an x86 system using C. My approach is run an empty for loop for a large amount of iterations. I will then measure the execution time of this to determine the MIPS. However, I need to know the number of instructions found in a single for loop iteration.
#include <stdio.h>
#include <sys/time.h>
int main(int argc, char *argv[])
{
size_t max_iterations = 1000000000;
// grab start time
for(int i = 0; i < max_iterations; i++)
{
// empty
}
// grab end time and calculate MIPS
printf("MIPS = %f\n", max_iterations * instruction_per_cycle / 1000000.0 / elapsed_sec);
return 0;
}
I'm unfamiliar with the x86 instruction set, however, for the for loop I've provided it seems like the following items could be instructions:
- load value i from memory to register
- load value max_iterations from memory to register
- perform comparison between i and max_iterations
- increment i
- write new value of i to memory
- jump into loop assuming
- jump back to start of loop statement