The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Farabi on February 15, 2009, 11:50:57 PM

Title: How many second 1 clock is?
Post by: Farabi on February 15, 2009, 11:50:57 PM
Anyone know how many second 1 clock cycle is?
Title: Re: How many second 1 clock is?
Post by: donkey on February 16, 2009, 12:04:39 AM
The frequency of your CPU is the number of clock cycles per second, a 1889.57 Mhz cpu has 1,889,570,000 cycles per second. Because of variations in CPUs and small fluctuations in actual frequency each CPU is different even if they are identical models so the question can only be answered on a machine by machine basis, there is no fixed answer.
Title: Re: How many second 1 clock is?
Post by: PBrennick on February 16, 2009, 12:17:11 AM
To amplify further ...

A counter is a general term used in programming to refer to an incrementing variable. Some systems include a high-resolution performance counter that provides high-resolution elapsed times.

If a high-resolution performance counter exists on the system, the QueryPerformanceFrequency function can be used to express the frequency, in counts per second. The value of the count is processor dependent. On some processors, for example, the count might be the cycle rate of the processor clock.
The QueryPerformanceCounter function retrieves the current value of the high-resolution performance counter (if one exists on the system). By calling this function at the beginning and end of a section of code, an application essentially uses the counter as a high-resolution timer. For example, suppose that QueryPerformanceFrequency indicates that the frequency of the high-resolution performance counter is 50,000 counts per second. If the application calls QueryPerformanceCounter immediately before and immediately after the section of code to be timed, the counter values might be 1500 counts and 3500 counts, respectively. These values would indicate that .04 seconds (2000 counts) elapsed while the code executed.

Paul
Title: Re: How many second 1 clock is?
Post by: Mark Jones on February 16, 2009, 04:14:04 AM
To add to the above, the mathematical formula is:


  1
Frequency  =  ----------
Period

and

  1
Period     =  ----------
Freq.


So a frequency of 1889.57MHZ, when 1 is divided by this (or so-called "reciprocated"), the period is 0.000000529 seconds. So each clock cycle takes this long.

Of course, this is the minimum duration possible. Most instructions take longer than one cycle, and due to modern processor architecture, may vary considerably. This is why timing routines take many samples of a function -- to arrive at an average execution time.
Title: Re: How many second 1 clock is?
Post by: Tedd on February 16, 2009, 12:02:10 PM
Just to complicate things further, your processor isn't necessarily running at full speed most of the time - they can be switched to run at 1/4, 1/2, 3/4 of the full speed as required, so unless you're doing something expensive it's unlikely to be running at the rated speed.
Title: Re: How many second 1 clock is?
Post by: PBrennick on February 16, 2009, 02:52:20 PM
... which is why you would set the priority to make sure the result is fairly dependable. Without setting a high priority, you run the risk of time slicing affecting your results to the point that they would make no sense.

This is fun, what we need is MichaelW to step in. He is the guy who worked this all out to a science.

Paul
Title: Re: How many second 1 clock is?
Post by: Farabi on February 18, 2009, 01:39:53 AM
THanks, I need time to understand it.