liveBook · Manning

Clock cycle

As explained in Modern C

A clock cycle is one period of a processor's clock signal used as a unit of execution time.

From loop time to cycles

A measured loop body takes about 1.77 × 10⁻⁸ seconds per iteration. On a 2.1 GHz laptop, that is roughly 36 clock cycles. Other measured loops take about 55, 61, and 67 cycles per iteration. section 15.3

A clock cycle is one period of a processor’s clock signal. Expressing elapsed time in cycles makes the cost of repeated computations easier to compare on the measured machine: replacing a simple sum with stats_collect1 adds about 19 cycles per iteration; successive statistical updates add about six cycles each. section 15.3

TAKEAWAY: These are estimates derived from measured time and the laptop’s clock frequency, not universal costs for the C statements. The measured loops have relative standard deviations below 1%; the arithmetic instructions, loads, and stores in an assembler listing provide a separate plausibility check. section 15.3

How Modern C covers it

How deep it goes
Works through converting measured loop times to approximate cycles and comparing costs; does not derive processor timing from individual instructions.
Examples
Uses four loop measurements on a 2.1 GHz laptop and compares a simple sum with three statistical update variants.
What it assumes
Assumes familiarity with C loops and measured execution time; introduces cycle counts through a concrete frequency and timings.
What you can do after
Evaluate/understand approximate per-iteration cycle costs and differences between measured loop implementations.
How it connects
Connects clock frequency, elapsed-time measurement, relative standard deviation, incremental statistics, and assembler inspection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.