14 lines
1.8 KiB
HTML
14 lines
1.8 KiB
HTML
<!doctype html><html lang="en"><meta charset="utf-8"><title>Measure repeated runs with a real clock</title><h1>Measure repeated runs with a real clock</h1><p>15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.</p><p>Use a monotonic high-resolution clock. Warm up separately, repeat a fixed workload, verify a checksum, and report median plus spread. Record units, data size, environment, and compiler/runtime version. The following measures Python sum on this CPU and includes interpreter/runtime costs; it is not a GPU or raw memory-bandwidth benchmark.</p><p><strong>Practice and evidence:</strong> Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.</p><pre><code class="language-python">import time,statistics,platform
|
|
data=list(range(100000))
|
|
expected=4999950000
|
|
assert sum(data)==expected
|
|
samples=[]
|
|
for _ in range(7):
|
|
start=time.perf_counter_ns()
|
|
result=sum(data)
|
|
samples.append((time.perf_counter_ns()-start)/1e6)
|
|
assert result==expected
|
|
print("CPU Python",platform.python_version(),platform.machine())
|
|
print("median_ms",round(statistics.median(samples),4))
|
|
print("min_ms",round(min(samples),4),"max_ms",round(max(samples),4))
|
|
</code></pre><h3>Practice and evidence</h3><p>Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.</p><p><a href="https://git.agilaos.com/matt/open_agx">Language reference: git.agilaos.com</a></p><p><a href="https://docs.nvidia.com/cuda/cuda-c-best-practices-guide/">Language reference: docs.nvidia.com</a></p></html> |