generated from carpentries/workbench-template-md
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9625f83
commit 2f2b3cd
Showing
7 changed files
with
204 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,6 +60,9 @@ contact: '[email protected]' | |
# Order of episodes in your lesson | ||
episodes: | ||
- introduction.md | ||
- profiling-introduction.md | ||
- profiling-functions.md | ||
- profiling-lines.md | ||
|
||
# Information for Learners | ||
learners: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
"file" "checksum" "built" "date" | ||
"CODE_OF_CONDUCT.md" "c93c83c630db2fe2462240bf72552548" "site/built/CODE_OF_CONDUCT.md" "2023-12-07" | ||
"LICENSE.md" "b24ebbb41b14ca25cf6b8216dda83e5f" "site/built/LICENSE.md" "2023-12-07" | ||
"config.yaml" "509085b79e6ec689b015216d87ddbeff" "site/built/config.yaml" "2023-12-08" | ||
"index.md" "a02c9c785ed98ddd84fe3d34ddb12fcd" "site/built/index.md" "2023-12-08" | ||
"config.yaml" "9086af5e5e979722dcad1ab925ec6412" "site/built/config.yaml" "2024-01-01" | ||
"index.md" "df8ef5258ba527e8fc3ca82f97fa27d8" "site/built/index.md" "2024-01-01" | ||
"links.md" "8184cf4149eafbf03ce8da8ff0778c14" "site/built/links.md" "2023-12-07" | ||
"episodes/introduction.md" "6c55d31b41d322729fb3276f8d4371fc" "site/built/introduction.md" "2023-12-07" | ||
"episodes/profiling-introduction.md" "2dbb9db1de2f82c16a27fc86076ca9f7" "site/built/profiling-introduction.md" "2024-01-01" | ||
"episodes/profiling-functions.md" "6e3d4d42db22b5ea2d9a112c61940289" "site/built/profiling-functions.md" "2024-01-01" | ||
"episodes/profiling-lines.md" "f21cb8b587a238657ac5bdf28df59e50" "site/built/profiling-lines.md" "2024-01-01" | ||
"instructors/instructor-notes.md" "cae72b6712578d74a49fea7513099f8c" "site/built/instructor-notes.md" "2023-12-07" | ||
"learners/reference.md" "1c7cc4e229304d9806a13f69ca1b8ba4" "site/built/reference.md" "2023-12-07" | ||
"learners/setup.md" "61568b36c8b96363218c9736f6aee03a" "site/built/setup.md" "2023-12-07" | ||
"learners/setup.md" "eda96a4aa0e52fe92f91868fb2ecd5c0" "site/built/setup.md" "2024-01-01" | ||
"profiles/learner-profiles.md" "60b93493cf1da06dfd63255d73854461" "site/built/learner-profiles.md" "2023-12-07" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: "Function Level Profiling" | ||
teaching: 0 | ||
exercises: 0 | ||
--- | ||
|
||
:::::::::::::::::::::::::::::::::::::: questions | ||
|
||
- TODO | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
::::::::::::::::::::::::::::::::::::: objectives | ||
|
||
- TODO | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
--- | ||
title: "Introduction to Profiling" | ||
teaching: 0 | ||
exercises: 0 | ||
--- | ||
|
||
:::::::::::::::::::::::::::::::::::::: questions | ||
|
||
- TODO | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
::::::::::::::::::::::::::::::::::::: objectives | ||
|
||
- explain the benefits of profiling code and different types of profiler | ||
- identify the appropriate Python profiler for a given scenario | ||
- explain how to select an appropriate test case for profiling and why | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
|
||
## Introduction | ||
|
||
<!-- Profiling is (what) --> | ||
<!-- It can be used for (where) --> | ||
<!-- This allows enables faster/more (why)--> | ||
<!-- It can be difficult to know without profiling, surprise speedup (why2) --> | ||
<!-- Increasingly, concern for green/eco compute and or cloud costs (why3) --> | ||
|
||
## Types of Profiler | ||
|
||
There are multiple approaches to profiling, most programming languages have one or more tools available covering these approaches. | ||
Whilst these tools differ, their core functionality can be grouped into four categories. | ||
|
||
### Manual Profiling | ||
|
||
Similar to using `print()` for debugging, manually timing sections of code can provide a rudimentary form of profiling. | ||
|
||
```Python | ||
import time | ||
|
||
t_a = time.monotonic() | ||
# A: Do something | ||
t_b = time.monotonic() | ||
# B: Do something else | ||
t_c = time.monotonic() | ||
# C: Do another thing | ||
t_d = time.monotonic() | ||
|
||
mainTimer_stop = time.monotonic() | ||
print(f"A: {t_b - t_a} seconds") | ||
print(f"B: {t_c - t_b} seconds") | ||
print(f"C: {t_d - t_c} seconds") | ||
``` | ||
|
||
*Above is only one example of how you could manually profile your Python code, there are many similar techniques.* | ||
|
||
Whilst this can be appropriate for profiling narrow sections of code, it becomes increasingly impractical as a project grows in size and complexity. | ||
Furthermore, it's also unproductive to be routinely adding and removing these small changes if they interfere with the required outputs of a project. | ||
|
||
::::::::::::::::::::::::::::::::::::: callout | ||
|
||
You may have previously used [`timeit`](https://docs.python.org/3/library/timeit.html) for timing Python code. | ||
|
||
This package returns the **total runtime** of an isolated block of code, without providing a more granular timing breakdown. | ||
Therefore, it is better described as a tool for **benchmarking**. | ||
|
||
::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
### Function-Level Profiling | ||
### Line-Level Profiling | ||
### Hardware Metric Profiling | ||
<!-- "Hardware" metric profilers also exist, but atypical for high-level languages like Python, so won't be covering. --> | ||
|
||
## | ||
|
||
<!-- Todo, how to frame data-set selection --> | ||
|
||
|
||
|
||
|
||
|
||
|
||
::::::::::::::::::::::::::::::::::::: discussion | ||
|
||
# Exercise (5 minutes) | ||
|
||
Think about a project where you've been working with Python. | ||
Do you know where the time during execution is being spent? | ||
|
||
Write a short plan of the approach you would take to investigate and confirm | ||
where the majority of time is being spent during it's execution. | ||
|
||
<!-- TODO should they share this anywhere, should it be discussed within the group? --> | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
::::::::::::::::::::::::::::::::::::: hint | ||
|
||
- What tools and techniques would be required? | ||
- Is there a clear priority to these approaches? | ||
- Which test-case/s would be appropriate? | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
|
||
::::::::::::::::::::::::::::::::::::: keypoints | ||
|
||
todo summarise lessons learned | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: "Line Level Profiling" | ||
teaching: 0 | ||
exercises: 0 | ||
--- | ||
|
||
:::::::::::::::::::::::::::::::::::::: questions | ||
|
||
- TODO | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: | ||
|
||
::::::::::::::::::::::::::::::::::::: objectives | ||
|
||
- TODO | ||
|
||
:::::::::::::::::::::::::::::::::::::::::::::::: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters