Empirical timings with perf_counter
time.perf_counter() returns a float timestamp from a monotonic clock suitable for deltas: subtract end from start to measure elapsed seconds. It is what you want for micro-benchmarks of NumPy calls, sklearn fit, or small pure-Python kernels—not time.time() (NTP adjustments can move backwards) and usually not time.process_time() alone if you care about wall-clock waits.
Empirical measurement is noisy: cold caches, JIT warm-up, other processes, and Python’s allocator all jitter results. Discard the first iteration, repeat, and report median or mean over several runs when comparing approaches.
For coursework, pairing asymptotic reasoning with a few timed curves (doubling n) builds intuition that Big-O alone cannot supply.
time.perf_counter docs: [1].
Sources
Tasks
Card Info
- Topic: Asymptotics & empirical timing
- Difficulty: Beginner
- Completed: 0 users