Skip to content

Commit 1359bb4

Browse files
speed_ex1: add fair end-to-end timing for pre-draw approach
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0cf0d7d commit 1359bb4

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

lectures/numba.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,20 @@ with qe.Timer():
526526
calculate_pi_in_loop(rng, n)
527527
```
528528

529+
The two cells timing the first approach measure only the loop --- its random
530+
points are drawn once in the shared setup block above and are never timed, while
531+
the second approach pays for its draws inside the timed function.
532+
533+
To compare the two approaches fairly, we time the first approach end-to-end,
534+
including the cost of generating the arrays:
535+
536+
```{code-cell} ipython3
537+
with qe.Timer():
538+
u2 = rng.uniform(size=n)
539+
v2 = rng.uniform(size=n)
540+
calculate_pi(u2, v2)
541+
```
542+
529543
In this serial setting the two approaches give equally good estimates and run at
530544
similar speed, but they are not equivalent in *memory use*.
531545

0 commit comments

Comments
 (0)