Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

What does clock frequency mean

What does clock frequency mean

Understand the real meaning of GHz, and why clock speed is not the only measure of CPU performance.


A life analogy: the metronome

Imagine a metronome -- a tool musicians use to practice rhythm. Set it to 120 beats per minute and it makes two 'tick' sounds per second.

The number of beats a metronome strikes per second is like a CPU's clock frequency. On each beat the musician plays a note; in each clock cycle the CPU may also execute an instruction. The faster the metronome, the faster the performance; likewise, the higher the CPU frequency, the more 'actions' completed per unit time.

But there is one key limit: if you set the metronome too fast -- say 600 beats per minute -- the player cannot keep up, plays wrong notes, or falls into complete chaos. The same goes for CPUs: frequency cannot be raised without limit; when it gets high enough it hits physical limits (power and heat dissipation problems), and that is exactly what this lecture explores in depth.

Definition of Hz and GHz

Hz (hertz) is the SI unit of frequency, representing the number of periodic events occurring per second. The unit is named after the German physicist Heinrich Hertz, who in 1888 first experimentally confirmed the existence of electromagnetic waves.

The unit conversions are as follows:

1 Hz = 1 cycle per second

1 kHz (kilohertz) = 1,000 Hz = 10^3 Hz

1 MHz (megahertz) = 1,000,000 Hz = 10^6 Hz

1 GHz (gigahertz) = 1,000,000,000 Hz = 10^9 Hz

Modern desktop CPUs typically run between 3 GHz and 5 GHz, which means the clock signal oscillates 3 to 5 billion times per second. For an intuitive comparison: a human heartbeat is about 1-2 Hz, a hummingbird's wings beat at about 50 Hz, while your phone's processor is running at about 3 GHz.

The relationship between clock period and frequency

The clock period (Clock Period) is the time required for the clock signal to complete one full oscillation (from high level to low level and back to high, or vice versa). Its relationship with frequency is very simple:

Clock period T = 1 / frequency f

For example, for a 4 GHz CPU, its clock period T = 1/4,000,000,000 = 0.25 nanoseconds (ns). Within this extremely short 0.25 ns, the CPU completes one basic operation step (such as one stage of fetch, decode, or execute).

In a vacuum, light travels only about 30 cm in 1 nanosecond -- that is, in a single clock cycle (0.25 ns) of a 4 GHz CPU, light can travel only about 7.5 cm. This means signal propagation delay inside the chip has become a limiting factor that cannot be ignored.

Frequency comparison of different clock sources

Clock source / processor Frequency Clock period Era / typical application
Quartz crystal oscillator 32.768 kHz About 30.5 microseconds Electronic watches, RTC real-time clock
Intel 4004 (first commercial microprocessor) 740 kHz About 1.35 microseconds 1971
Intel 8086 (IBM PC) 5-10 MHz 100-200 nanoseconds 1978
Intel 80486 25-100 MHz 10-40 nanoseconds 1989
Intel Pentium series 60-300 MHz 3.3-16.7 nanoseconds 1993-1999
Intel Pentium 4 (NetBurst architecture) 1.3-3.8 GHz 0.26-0.77 nanoseconds 2000-2005
Modern desktop processors (Core i9 / Ryzen 9) 3-5.7 GHz 0.18-0.33 nanoseconds Current
Modern mobile processors (Apple M series, etc.) 2-4 GHz 0.25-0.5 nanoseconds Current

From the table above, CPU frequency increased more than a thousandfold over 25 years. But after the Pentium 4 era, the growth of frequency clearly slowed -- behind this are exactly the effects of the power wall and the frequency wall.

Why clock speed is not the only measure of performance

4.1 IPC: Instructions Per Cycle

IPC (Instructions Per Cycle) is a core metric for measuring CPU architecture efficiency, indicating how many instructions the CPU can execute on average in each clock cycle.

Overall performance can be approximately described by the following formula:

Performance = clock speed x IPC

For example: CPU A at 4 GHz with IPC 2 executes 4 billion x 2 = 8 billion instructions per second. CPU B at 3 GHz with IPC 4 executes 3 billion x 4 = 12 billion instructions per second. Although B's clock speed is 25% lower, because its IPC is twice as high, its actual performance is instead 50% higher.

This explains why the low-clock Apple M1/M2 can match or surpass high-clock Intel/AMD processors in single-core performance -- their IPC is very high.

4.2 Multiple factors affecting performance

Influencing factor Description Impact on actual performance
Clock frequency (clock speed) Number of clock cycles per second, in Hz Directly related, but constrained by physical limits
IPC (instructions per cycle) Core metric of architecture efficiency Extremely high
Pipeline depth Splits instruction execution into multiple stages processed in parallel High, but the penalty is also large when branch prediction fails
Superscalar and out-of-order execution Issues multiple instructions per cycle, not in program order Extremely high
Cache size and hierarchy L1/L2/L3 cache capacity, speed, and hit rate Extremely high
Branch predictor Guesses the outcome of branch instructions in advance High; a misprediction costs 10-20 cycles
Number of cores Capability for multi-core parallel processing Depends on whether the program is sufficiently multithreaded
Manufacturing process Transistor size, e.g. 5nm, 3nm Indirectly affects power, frequency ceiling, and transistor density
Memory bandwidth and latency Data transfer speed between the CPU and main memory High; often becomes a bottleneck ("memory wall")

4.3 Power wall and frequency wall

In the early 2000s, Intel once drew up a roadmap predicting that CPU clock speeds would reach 10 GHz by 2010. But in reality clock speed hit a ceiling around 4-5 GHz, which is called the "Frequency Wall".

The root cause lies in the Power Wall. The dynamic power of CMOS circuits is approximated by: P = C x V^2 x f, where C is the capacitive load, V is the operating voltage, and f is the frequency. Raising frequency requires raising voltage at the same time (otherwise transistors cannot complete state switching in time), and power is proportional to the square of voltage -- this means the price of higher frequency is a sharp rise in power consumption.

When a chip's power consumption reaches 100-150W, conventional cooling methods (air cooling, water cooling) become very difficult. Pushing frequency higher still will damage the chip through overheating. This is why the power wall limits the frequency wall.

For this reason, modern CPU design no longer simply pursues high clock speed, but turns toward multi-core, higher IPC, and optimizing power efficiency.

When choosing a CPU, please do not look only at the clock speed (GHz). Two CPUs both at 3.5 GHz can differ in actual performance by more than a factor of two due to differences in architecture, IPC, cache, process, and so on. The most reliable way to evaluate CPU performance is to look at benchmark (Benchmark) results for real application scenarios.

Interactive demo

Drag the slider below to change the frequency and watch the green square flash at the set frequency. When you set the frequency to 30 Hz, the square looks almost constantly lit -- this is the persistence-of-vision effect of the human eye. A real CPU runs at the GHz level, far beyond human perception.

CPU clock frequency visualization (runoob demo)

Current frequency

2.0 Hz

Clock period

500 ms

Cumulative ticks

0

2.0

Status: running

Tip: 1 Hz = 1 flash per second. The human eye can roughly distinguish flicker below 20-30 Hz. But a real CPU runs at the GHz level -- billions of times per second, completely imperceptible to the naked eye. This demo helps you intuitively understand the core concept "frequency = actions per second".

Python code demo

The Python code below demonstrates how to compute the time needed to execute N instructions at different frequencies and IPC values. You can intuitively see the respective impact of clock speed and IPC on performance:

Example

runoob test: clock frequency and instruction execution time calculation

def

calc_execution_time

(

frequency_ghz

,

num_instructions

,

ipc

=

1.0

)

:

   

"""
    Compute the time required to execute a given number of instructions at a given frequency.

    Parameters:
        frequency_ghz: CPU clock speed, in GHz
        num_instructions: total number of instructions to execute
        ipc: instructions per cycle (Instructions Per Cycle), default 1.0

    Returns:
        float: execution time, in seconds
    """

    cycles_per_second

=

frequency_ghz *

1

_000_000_000

    instructions_per_second

=

cycles_per_second * ipc

   

return

num_instructions / instructions_per_second

def

format_time

(

seconds

)

:

   

"""Format a number of seconds into a human-readable string"""

   

if

seconds

=

1

:

       

return

f

"{seconds:.3f} seconds"

   

elif

seconds

=

0.001

:

       

return

f

"{seconds * 1000:.3f} milliseconds"

   

elif

seconds

=

0.000001

:

       

return

f

"{seconds * 1000000:.3f} microseconds"

   

else

:

       

return

f

"{seconds * 1e9:.3f} nanoseconds"

def

main

(

)

:

    NUM_INST

=

1

_000_000_000  

1 billion instructions

   

print

(

"="

58

)

   

print

(

" runoob clock frequency and CPU performance demo"

)

   

print

(

"="

58

)

   

print

(

f

" Total instructions executed: {NUM_INST:,} instructions"

)

   

print

(

)

   

Test different combinations of frequency and IPC

    frequencies

=

[

1.0

,

2.0

,

3.0

,

4.0

,

5.0

]

    ipc_values

=

[

1.0

,

2.0

]

    header

=

f

" {'Frequency(GHz)':>10}"

   

for

ipc

in

ipc_values:

        header +

=

f

" | {'IPC=' + str(int(ipc)) + ' Time':>14}"

   

print

(

header

)

   

print

(

"  "

"-"

(

len

(

header

)

2

)

)

   

for

f

in

frequencies:

        row

=

f

"  {f:>10.1f}"

       

for

ipc

in

ipc_values:

            t

=

calc_execution_time

(

f

,

NUM_INST

,

ipc

)

            row +

=

f

" | {format_time(t):>14}"

       

print

(

row

)

   

Key comparison: low clock + high IPC vs high clock + low IPC

   

print

(

)

   

print

(

" === Key comparison: architecture vs clock speed ==="

)

    t_a

=

calc_execution_time

(

3.0

,

NUM_INST

,

ipc

=

2.0

)

    t_b

=

calc_execution_time

(

5.0

,

NUM_INST

,

ipc

=

1.0

)

   

print

(

f

"  CPU A (3.0 GHz, IPC=2): {format_time(t_a)}"

)

   

print

(

f

"  CPU B (5.0 GHz, IPC=1): {format_time(t_b)}"

)

   

if

t_a

<

t_b:

        speedup

=

t_b / t_a

       

print

(

f

" Conclusion: low frequency + high IPC wins! CPU A is {speedup:.2f}x faster than CPU B"

)

   

else

:

       

print

(

f

" Conclusion: high frequency wins, but the gap is far smaller than the frequency ratio"

)

   

Effect of doubling frequency on execution time

   

print

(

)

   

print

(

" === Frequency doubling test ==="

)

   

for

base_freq

in

[

1.0

,

2.0

]

:

        t1

=

calc_execution_time

(

base_freq

,

NUM_INST

,

ipc

=

1.0

)

        t2

=

calc_execution_time

(

base_freq *

2

,

NUM_INST

,

ipc

=

1.0

)

       

print

(

f

"  {base_freq} GHz -> {base_freq*2} GHz: "

              f

"{format_time(t1)} -> {format_time(t2)} "

              f

"(reduced to {t2/t1*100:.0f}%)"

)

main

(

)

Interactive demo: CSS animation frequency flasher

The demo below uses pure CSS @keyframes animation to make the square flash. Drag the slider to change the frequency; the animation's animation-duration will be adjusted in real time.Compare the two demos above and below: the previous one switches styles with JS; this one directly modifies the CSS animation speed -- both implementations demonstrate the same core concept.

CSS Animation frequency flasher (runoob demo)

Current frequency

2.0 Hz

Clock period

500 ms

animation-duration

0.50 s

2.0

Tip: the square flashes via a CSS

@keyframes

animation.

animation-duration

property is computed in real time by JS from the slider value: duration = 1 / frequency.

Frequency 0.5 Hz = one flash every 2 seconds; frequency 10 Hz = 10 flashes per second.

When the frequency is high, the human eye can hardly distinguish a single flash cycle -- but the CSS animation is still running precisely.