Skip to content

Commit 9538d56

Browse files
committed
convert %time to qe.Timer()
1 parent 93b664a commit 9538d56

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lectures/numba.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,13 @@ This is equivalent to adding `qm = jit(qm)` after the function definition.
227227
The following now uses the jitted version:
228228

229229
```{code-cell} ipython3
230-
%%time
231-
232-
qm(0.1, 100_000)
230+
with qe.Timer():
231+
qm(0.1, 100_000)
233232
```
234233

235234
```{code-cell} ipython3
236-
%%time
237-
238-
qm(0.1, 100_000)
235+
with qe.Timer():
236+
qm(0.1, 100_000)
239237
```
240238

241239
Numba also provides several arguments for decorators to accelerate computation and cache functions -- see [here](https://numba.readthedocs.io/en/stable/user/performance-tips.html).
@@ -291,7 +289,8 @@ We can fix this error easily in this case by compiling `mean`.
291289
def mean(data):
292290
return np.mean(data)
293291
294-
%time bootstrap(data, mean, n_resamples)
292+
with qe.Timer():
293+
bootstrap(data, mean, n_resamples)
295294
```
296295

297296
## Compiling Classes
@@ -536,11 +535,13 @@ def calculate_pi(n=1_000_000):
536535
Now let's see how fast it runs:
537536

538537
```{code-cell} ipython3
539-
%time calculate_pi()
538+
with qe.Timer():
539+
calculate_pi()
540540
```
541541

542542
```{code-cell} ipython3
543-
%time calculate_pi()
543+
with qe.Timer():
544+
calculate_pi()
544545
```
545546

546547
If we switch off JIT compilation by removing `@njit`, the code takes around

0 commit comments

Comments
 (0)