views:

163

answers:

2

Can increment of a register (in a loop) be used to determine the (effective) clock rate? I've naturally assumed it can, but I was commented that Cpu's may implant Super-scalar techniques that make this kind of computation useless. Also I was told that incrementing of registers on CPU can be done in less than one clock cycle.

is it true?

+1  A: 

No, you can't use that to determine clock rate. There is no guarantee that a register can be incremented exactly once per clock.

What CPU are you targeting? There are more definite ways of determine clock rate, at least on x86.

Michael
It was a general question, but I'm definitely interested in x86...
Liran Orevi
+3  A: 

No, not reliably. The number of cycles that it takes to increment a register can vary between different types of processors, and you also have to include the overhead of looping. In any modern operating system, you're going to have to deal with preemptive multitasking, so you have no idea how much CPU time the process scheduler is going to give you. Depending on how much work other processes are doing, you may get a lot or a little CPU time, so the number of register increments you can perform per second is highly variable.

Furthermore, in a multicore environment, the clocks may not tick at the same rate. If your process gets moved between cores by the scheduler for some reason or another, your clock rate could change unpredictably.

There are much better ways of getting the clock rate, such as asking the operating system for it (of course, how to do this varies with OS).

Adam Rosenfield
Maybe Linux 'time' will give me a better estimate on the time actually spend on a process, but I understand your point, thanks.
Liran Orevi