CPU需要多长时间才能执行单个命令? [英] How long time does CPU need to execute a single command?
本文介绍了CPU需要多长时间才能执行单个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你能告诉我如何计算CPU使用的时间吗?
例如:
------- ---------------
Can you tell me how to calculate the time which CPU had used?
Example:
----------------------
public int Main()
{
int a, b, c;
a = 1; b = 2;
return (c = a + b);
}
----------------------
如果我们忽略这些时间:编译,提供varibles存储,将数据加载到堆栈/堆...
然后,如何知道要执行的纳秒数CPU寄存器的这个命令:
----------------------
If we ignore these time: compiling, provide varibles storage, load data to stack/heap...
Then, how to know the nanoseconds to execute this command by CPU Registers:
return (c = a + b);
感谢您的解决方案!
Thanks for solutions!
推荐答案
添加是一个机器指令,复制到缓冲区是另一个,所以2个时钟周期是绝对最低限度。所以 - .00000005秒(+/- 100%)
The addition is one machine instruction, and copying into a buffer is another so 2 clock cycles is the absolute minimum. So - .00000005 seconds (+/- 100%)
我不明白你需要什么,为什么......
但我可以将你重定向到Mr.Robert的文章。
关于:: 如何:用C#测量执行时间 [ ^ ] ::
你不能。取决于CPU的运行速度,运行的指令集,JIT的作用,是否内联或分支等。
You can't. Depends on what speed the CPU is clocked at, what instruction set its running, what the JIT does, whether it gets 'inlined' or branched etc.
这篇关于CPU需要多长时间才能执行单个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文