In: Computer Science
Two different compilers are being tested for a 4 GHz. machine with three different classes of instructions: Class A, Class B, and Class C, which require one, two, and three cycles per instruction (respectively). Both compilers are used to produce code for a large piece of software. The first compiler's code uses 5 million Class A instructions, 1 million Class B instructions, and 1 million Class C instructions. The second compiler's code uses 10 million Class A instructions, 1 million Class B instructions, and 1 million Class C instructions. Which sequence will be faster according to MIPS? Which sequence will be faster according to execution time?
Frequency of the machine is 4 GHz.
So, 4*109 clock cycles require 1 second to execute.
Therefore, 1 clock cycle time will be = 0.25*10-9 seconds.
1st Compiler:
Total number of clock cycles to require to execute all instructions = 5*1 + 1*2 + 1*3 = 5 + 2 + 3 = 10 million clock cycles.
Therefore, the execution time of these instructions = 10*106*0.25*10-9 = 2.5*10-3 seconds or 2.5 ms.
Now, 2.5*10-3 seconds is required to execute a total of 7*106 instructions.
Therefore, in 1-second number of instructions executed = 7*106 / 2.5*10-3 = 2.8*109 instructions or 2800 MIPS
2nd Compiler:
Total number of clock cycles to require to execute all instructions = 10*1 + 1*2 + 1*3 = 10 + 2 + 3 = 15 million clock cycles.
Therefore, the execution time of these instructions = 15*106*0.25*10-9 = 3.75*10-3 seconds or 3.75 ms.
Now, 3.75*10-3 seconds is required to execute a total of 12*106 instructions.
Therefore, in 1-second number of instructions executed = 12*106 / 3.75*10-3 = 3.2*109 instructions or 3200 MIPS
According to MIPS, 2nd compiler is faster.
According to execution time, 1st compiler is faster.