计算哪个编译器在循环方面更快



我只是有一个简单的问题,有点傻,但我只需要为即将到来的考试做一些澄清,这样我就不会犯一个愚蠢的错误。我目前正在上计算机组织和设计课程,并正在学习执行时间、CPI、时钟周期等。

对于一个问题,我必须计算 2 个编译器的周期数,并找出哪个更快,以及给定指令数和每个指令的周期数。我的主要问题是弄清楚更快的编译器有多快。

例如,假设有两个编译器:

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 

加载指令需要 2 个周期,存储指令需要 3 个周期,添加指令需要 1 个周期

所以我要做的是指令 (3+4+5) 和 (5+4+3),它们都等于 12 条指令。

然后,我将通过将指令数乘以周期并将它们全部相加来计算周期,如下所示

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

所以很明显编译器 1 更快,因为它需要更少的周期。要找出编译器 1 与编译器 2 相比快多少,我会只划分周期的比率吗?

我的计算是 23/25 = 0.92,所以编译器 1 比编译器 2 快 0.92 倍(快 92%)。

我的一个同学正在和我讨论这个问题,并声称这将是 25/23,这意味着它快 1.08 倍。

我知道我也可以通过将周期除以以下指令来计算这一点:

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. 

我不确定哪种方式是正确的。

我也想知道第二个编译器的指令数量是否不同,假设 15 条指令。计算周期的比率是否足够?

还是我必须用指令(周期/指令)划分周期,但为两者放置 15 条指令?

(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. 

感谢您的任何澄清。

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

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

最新更新