1

I just have a simple question, a bit silly, but I just need some clarification for an upcoming exam so I don't make a stupid mistake. I am currently taking a class in computer organization and design and am learning about execution time, CPI, clock cycles, etc.

For a problem, I have to calculate the amount of cycles for 2 compilers and find out which one is faster and by how much given the number of instructions and the cycles for each instruction. My main problem is figuring how much faster the faster compiler is.

For example lets say their are two compilers:

Compiler 1 has 3 load instructions, 4 store instructions, and 5 add 
instructions.

Compiler 2 has 5 load instructions, 4 store instructions, and 3 add 
instructions 

A load instruction takes 2 cycles, a store instruction takes 3 cycles and a add instruction takes 1 cycle

So what I would do this add up to the instructions (3+4+5) and (5+4+3) which both equal to 12 instructions.

I'd then calculate the cycles by multiplying the number of instructions by the cycles and adding them all together like this

Compiler 1: (3*2)+(4*3)+(5*1) = 23 cycles 
Compiler 2: (5*2)+(4*3)+(3*1) = 25 cycles 

So obviously compiler 1 is faster because it requires less cycles. To find out how much faster compiler 1 is against compiler 2 would I just divide the ratio of the cycles?

My calculation was 23/25 = 0.92, so compiler 1 is 0.92 times faster than compiler 2 (92% faster).

A classmate of mine was discussing this with me and claims that it would be 25/23 which would mean it is 1.08 times faster.

I know I can also calculate this by dividing the cycles by the instructions like:

23 cycles/12 instructions = 1.91 
25 cycles/12 instructions = 2.08 
and then 1.91/2.08 = 0.92 which is the same as the above answer. 

I'm not sure which way would be correct.

I was also wondering if the amount of instructions are difference for the second compiler, let's say 15 instructions. Would calculating the ratio of the cycles be sufficient enough?

Or would I have to divide the cycles with the instructions (cycles/instructions) but put 15 instructions for both?

(ex. 23/15 and 25/15?) and then divide the quotients of both to get 
the times faster? I also get the same number(0.92) in that case. 

Thank you for any clarification.

4

2 回答 2

3

第一个编译器的速度是第二个编译器的 1.08 倍,快8%(因为 1.0 + 0.08 = 1.08)。

于 2019-04-08T09:31:07.197 回答
0

可能这两种计算都是不准确的,对于现代/多核处理器,生成更多指令的编译器实际上可能会产生更快的代码。

于 2019-04-08T06:38:48.183 回答