Why does a finer clock suddenly show real times, and what does it look like when a function's runtime never moves at all?
Short drills on what this video just taught. Write the code, run the checks, and reveal the answer only if you are stuck.
The ordinary clock moves in whole ticks of about a thousandth of a second: at any instant it shows the last tick that has passed, not the nearest one, so 12.3456 seconds reads as 12.345. The // operator may be useful. Define tick_reading(instant, tick) that returns what a clock with tick size tick shows at the true time instant (both in seconds).
Resolution of the performance counter versus time.time()
Write the two resolutions side by side - about seconds for time.perf_counter() and about for time.time() - and record that short functions once timed at zero now show a real time.
The timing recipe as a difference
List the steps - read the counter into t, call the function, read again, subtract for dt - and record that the counter gives a position in a time frame, not an absolute date.
Input sizes as powers of ten
Write the loop that builds L_N from [1] by appending L_N[-1]*10 eight times, list the nine sizes up to , and trace the timing loop that prints dt and 1/dt for each N.
Constant time: convert_to_km across eight orders of magnitude
Copy convert_to_km and its timing table, record that every input from 10 to takes between 3.00e-07 and 7.00e-07 seconds, and write the outlying first row's 4.30e-06 as seconds.