You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: episodes/profiling-lines.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ exercises: 30
27
27
Whilst profiling, you may find that function-level profiling highlights expensive methods where you can't easily determine the cause of the cost due to their complexity.
28
28
29
29
<!-- What -->
30
-
Line level profiling allows you to target specific methods to collect more granular metrics, which can help narrow the source of expensive computation further. Typically line-level profiling will calculate the number of times each line is called and the total time spent executing each line. However, with the increased granularity come increased collection costs, which is why it's targeted to specific methods.
30
+
Line level profiling allows you to target specific methods to collect more granular metrics, which can help narrow the source of expensive computation further. Typically, line-level profiling will calculate the number of times each line is called and the total time spent executing each line. However, with the increased granularity come increased collection costs, which is why it's targeted to specific methods.
31
31
32
32
<!-- Why -->
33
33
This allows lines that occupy a disproportionate amount of the total runtime to be quickly identified and investigated.
@@ -263,7 +263,7 @@ The `-r` argument passed to `kernprof` (or `line_profiler`) enables rich output,
263
263
264
264
## line_profiler Inside Notebooks
265
265
266
-
If you're more familiar with writing Python inside Jupyter notebooks you can, as with `snakeviz`, use `line_profiler` directly from inside notebooks. However it is still necessary for the code you wish to profile to be placed within a function.
266
+
If you're more familiar with writing Python inside Jupyter notebooks you can, as with `snakeviz`, use `line_profiler` directly from inside notebooks. However, it is still necessary for the code you wish to profile to be placed within a function.
267
267
268
268
First `line_profiler` must be installed and it's extension loaded.
269
269
@@ -282,7 +282,7 @@ The functions to be line profiled are specified with `-f <function name>`, this
282
282
283
283
This is followed by calling the function which runs the full code to be profiled.
284
284
285
-
For the above fizzbuzz example it would be:
285
+
For the above FizzBuzz example it would be:
286
286
287
287
```py
288
288
%lprun -f fizzbuzz fizzbuzz(100)
@@ -522,7 +522,7 @@ From the profiling output it can be seen that lines 285-287 occupy over 90% of t
522
522
523
523
Given that the following line 289 only has a relative 0.6% time, it can be understood that the vast majority of times the condition `prey.life < PREY_HUNGER_THRESH` is evaluated it does not proceed.
524
524
525
-
Remembering that this method is executed once per each of the 5000 `Grass` agents each step of the model, it could make sense to pre-filter `prey_list` once each timestep before it is passed to `Grass::eaten()`. This would greatly reduce the number of `Prey` iterated, reducing the cost of the method.
525
+
Remembering that this method is executed once per each of the 5000 `Grass` agents each step of the model, it could make sense to pre-filter `prey_list` once each time step before it is passed to `Grass::eaten()`. This would greatly reduce the number of `Prey` iterated, reducing the cost of the method.
526
526
527
527
:::::::::::::::::::::::::::::::::
528
528
::::::::::::::::::::::::::::::::::::::::::::::::
@@ -532,7 +532,7 @@ Remembering that this method is executed once per each of the 5000 `Grass` agent
532
532
533
533
- Specific methods can be line-level profiled if decorated with `@profile` that is imported from `line_profiler`.
0 commit comments