Skip to content

Commit 54d9daf

Browse files
Copilotmmcky
andcommitted
Migrate qe.timeit instances back to qe.Timer() with milliseconds for SciPy
Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com>
1 parent 2ae4cbf commit 54d9daf

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lectures/parallelization.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ x, y = np.meshgrid(grid, grid)
166166
```
167167

168168
```{code-cell} ipython3
169-
qe.timeit(lambda: np.max(f(x, y)), runs=3)
169+
with qe.Timer():
170+
np.max(f(x, y))
170171
```
171172

172173
If you have a system monitor such as htop (Linux/Mac) or perfmon
@@ -198,7 +199,8 @@ np.max(f_vec(x, y)) # Run once to compile
198199
```
199200

200201
```{code-cell} ipython3
201-
qe.timeit(lambda: np.max(f_vec(x, y)), runs=3)
202+
with qe.Timer():
203+
np.max(f_vec(x, y))
202204
```
203205

204206
At least on our machine, the difference in the speed between the
@@ -248,7 +250,8 @@ np.max(f_vec(x, y)) # Run once to compile
248250
```
249251

250252
```{code-cell} ipython3
251-
qe.timeit(lambda: np.max(f_vec(x, y)), runs=3)
253+
with qe.Timer():
254+
np.max(f_vec(x, y))
252255
```
253256

254257
Now our code runs significantly faster than the NumPy version.

lectures/scipy.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,13 @@ brentq(f, 0, 1)
321321
Here the correct solution is found and the speed is better than bisection:
322322

323323
```{code-cell} ipython
324-
qe.timeit(lambda: brentq(f, 0, 1), runs=3)
324+
with qe.Timer(unit="milliseconds"):
325+
brentq(f, 0, 1)
325326
```
326327

327328
```{code-cell} ipython
328-
qe.timeit(lambda: bisect(f, 0, 1), runs=3)
329+
with qe.Timer(unit="milliseconds"):
330+
bisect(f, 0, 1)
329331
```
330332

331333
### Multivariate Root-Finding

0 commit comments

Comments
 (0)