Measuring elapsed time [ref]
Problem¶
- Record two timestamps with
time.timeand compute elapsed seconds. - Measure how long
sum(range(1000))takes usingtime.perf_counter. - Test whether the second elapsed duration is a float.
Python solution¶
import time
start = time.time()
end = time.time()
elapsed = end - start
isinstance(elapsed, float) # True
start = time.perf_counter()
sum(range(1000))
elapsed = time.perf_counter() - start
isinstance(elapsed, float) # True
isinstance(elapsed, float) # True
Links¶
- Bubble sort (DSA)
- Heap sort (DSA)
- Quick sort (DSA)