generated from carpentries/workbench-template-md
-
Notifications
You must be signed in to change notification settings - Fork 3
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
0 parents
commit 209eacc
Showing
44 changed files
with
7,481 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
--- | ||
title: "Contributor Code of Conduct" | ||
--- | ||
|
||
As contributors and maintainers of this project, | ||
we pledge to follow the [The Carpentries Code of Conduct][coc]. | ||
|
||
Instances of abusive, harassing, or otherwise unacceptable behavior | ||
may be reported by following our [reporting guidelines][coc-reporting]. | ||
|
||
|
||
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html | ||
[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html |
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,79 @@ | ||
--- | ||
title: "Licenses" | ||
--- | ||
|
||
## Instructional Material | ||
|
||
All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry) | ||
instructional material is made available under the [Creative Commons | ||
Attribution license][cc-by-human]. The following is a human-readable summary of | ||
(and not a substitute for) the [full legal text of the CC BY 4.0 | ||
license][cc-by-legal]. | ||
|
||
You are free: | ||
|
||
- to **Share**---copy and redistribute the material in any medium or format | ||
- to **Adapt**---remix, transform, and build upon the material | ||
|
||
for any purpose, even commercially. | ||
|
||
The licensor cannot revoke these freedoms as long as you follow the license | ||
terms. | ||
|
||
Under the following terms: | ||
|
||
- **Attribution**---You must give appropriate credit (mentioning that your work | ||
is derived from work that is Copyright (c) The Carpentries and, where | ||
practical, linking to <https://carpentries.org/>), provide a [link to the | ||
license][cc-by-human], and indicate if changes were made. You may do so in | ||
any reasonable manner, but not in any way that suggests the licensor endorses | ||
you or your use. | ||
|
||
- **No additional restrictions**---You may not apply legal terms or | ||
technological measures that legally restrict others from doing anything the | ||
license permits. With the understanding that: | ||
|
||
Notices: | ||
|
||
* You do not have to comply with the license for elements of the material in | ||
the public domain or where your use is permitted by an applicable exception | ||
or limitation. | ||
* No warranties are given. The license may not give you all of the permissions | ||
necessary for your intended use. For example, other rights such as publicity, | ||
privacy, or moral rights may limit how you use the material. | ||
|
||
## Software | ||
|
||
Except where otherwise noted, the example programs and other software provided | ||
by The Carpentries are made available under the [OSI][osi]-approved [MIT | ||
license][mit-license]. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
## Trademark | ||
|
||
"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library | ||
Carpentry" and their respective logos are registered trademarks of [Community | ||
Initiatives][ci]. | ||
|
||
[cc-by-human]: https://creativecommons.org/licenses/by/4.0/ | ||
[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode | ||
[mit-license]: https://opensource.org/licenses/mit-license.html | ||
[ci]: https://communityin.org/ | ||
[osi]: https://opensource.org |
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,20 @@ | ||
--- | ||
title: Acknowledgements | ||
--- | ||
|
||
**Funding** | ||
|
||
The development of this course was funded by the [University of Sheffield](https://www.sheffield.ac.uk) to support researchers working with their [Stanage](https://docs.hpc.shef.ac.uk/en/latest/stanage/index.html#gsc.tab=0) HPC system. | ||
|
||
**Authorship** | ||
|
||
The initial materials were authored by [Robert Chisholm](https://www.sheffield.ac.uk/dcs/people/research-staff/robert-chisholm), with support from various colleagues within the university's [Research Software Engineering](https://rse.shef.ac.uk) and [Research IT](https://www.sheffield.ac.uk/it-services/research) teams. | ||
|
||
Additional consulting was provided by James Kilbane a close friend (and general rubber duck). | ||
|
||
**Resources** | ||
|
||
Most of the content was drawn from the education and experience of the author, however the below resources provided inspiration: | ||
|
||
* [High Performance Python, 2nd Edition](https://www.oreilly.com/library/view/high-performance-python/9781492055013/): This excellent book goes far deeper than this short course in explaining how to maximise performance in Python, however it inspired the examples; [memory allocation is not free](optimisation-memory.html#memory-allocation-is-not-free) and [vectorisation](optimisation-memory.html#memory-allocation-is-not-free). | ||
* [What scientists must know about hardware to write fast code](https://viralinstruction.com/posts/hardware/): This notebook provides an array of hardware lessons relevant to programming for performance, which could be similarly found in most undergraduate Computer Science courses. Although the notebook is grounded in Julia, a lower level language than Python, it is referring to hardware so many of same lessons are covered in the [memory episode](optimisation-memory.html). |
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,90 @@ | ||
#------------------------------------------------------------ | ||
# Values for this lesson. | ||
#------------------------------------------------------------ | ||
|
||
# Which carpentry is this (swc, dc, lc, or cp)? | ||
# swc: Software Carpentry | ||
# dc: Data Carpentry | ||
# lc: Library Carpentry | ||
# cp: Carpentries (to use for instructor training for instance) | ||
# incubator: The Carpentries Incubator | ||
carpentry: 'incubator' | ||
|
||
# Overall title for pages. | ||
title: 'Performance Profiling & Optimisation (Python)' | ||
|
||
# Date the lesson was created (YYYY-MM-DD, this is empty by default) | ||
created: ~ # FIXME | ||
|
||
# Comma-separated list of keywords for the lesson | ||
keywords: 'python, profiling, optimisation, data structures, algorithms' | ||
|
||
# Life cycle stage of the lesson | ||
# possible values: pre-alpha, alpha, beta, stable | ||
life_cycle: 'pre-alpha' | ||
|
||
# License of the lesson | ||
license: 'CC-BY 4.0' | ||
|
||
# Link to the source repository for this lesson | ||
source: 'https://github.com/RSE-Sheffield/pando-python' | ||
|
||
# Default branch of your lesson | ||
branch: 'main' | ||
|
||
# Who to contact if there are any issues | ||
contact: '[email protected]' | ||
|
||
# Navigation ------------------------------------------------ | ||
# | ||
# Use the following menu items to specify the order of | ||
# individual pages in each dropdown section. Leave blank to | ||
# include all pages in the folder. | ||
# | ||
# Example ------------- | ||
# | ||
# episodes: | ||
# - introduction.md | ||
# - first-steps.md | ||
# | ||
# learners: | ||
# - setup.md | ||
# | ||
# instructors: | ||
# - instructor-notes.md | ||
# | ||
# profiles: | ||
# - one-learner.md | ||
# - another-learner.md | ||
|
||
# Order of episodes in your lesson | ||
episodes: | ||
- profiling-introduction.md | ||
- profiling-functions.md | ||
- profiling-lines.md | ||
- profiling-conclusion.md | ||
- optimisation-introduction.md | ||
- optimisation-data-structures-algorithms.md | ||
- optimisation-minimise-python.md | ||
- optimisation-use-latest.md | ||
- optimisation-memory.md | ||
- optimisation-conclusion.md | ||
|
||
# Information for Learners | ||
learners: | ||
- setup.md | ||
- acknowledgements.md | ||
|
||
# Information for Instructors | ||
instructors: | ||
|
||
# Learner Profiles | ||
profiles: | ||
|
||
# Customisation --------------------------------------------- | ||
# | ||
# This space below is where custom yaml items (e.g. pinning | ||
# sandpaper and varnish versions) should live | ||
|
||
varnish: RSE-Sheffield/uos-varnish@main | ||
url: 'rse.shef.ac.uk/pando-python' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,29 @@ | ||
""" | ||
Construct a graph demonstrating the number of re-allocations | ||
if growing a CPython List with append() | ||
""" | ||
t = 0 | ||
a = 0 | ||
x = range(1000000) | ||
|
||
allocs = [0 for x in range(1000000)] | ||
while t < 1000000: | ||
t += 1 | ||
t_old = t | ||
# https://github.com/python/cpython/blob/a571a2fd3fdaeafdfd71f3d80ed5a3b22b63d0f7/Objects/listobject.c#L74 | ||
t = t + (t >> 3) + 6 | ||
a+=1 | ||
for k in range(t_old, t+1): | ||
if k < len(allocs): | ||
allocs[k] = a | ||
|
||
import matplotlib.pyplot as plt | ||
|
||
plt.plot(x, allocs) | ||
|
||
plt.xlabel("Appends") | ||
plt.ylabel("Resizes") | ||
#plt.ticklabel_format(style='plain') | ||
#plt.xscale('symlog') | ||
plt.savefig('cpython_list_allocations.png') | ||
plt.show() |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,20 @@ | ||
""" | ||
Construct a graph demonstrating the difference in latencies relevant to code execution | ||
Inspired by | ||
https://gist.github.com/jboner/2841832 | ||
Using data from | ||
https://www.intel.com/content/www/us/en/developer/articles/technical/memory-performance-in-a-nutshell.html | ||
""" | ||
import matplotlib.pyplot as plt | ||
label = ["L1 cache", "L2 cache", "L3 cache", "RAM", "SSD", "HDD", "Ldn->Ca->Ldn"] | ||
latency_ns = [1, 4, 40, 80, 8000, 80000, 140000000] | ||
|
||
plt.figure().set_figheight(2) | ||
plt.barh(label, latency_ns) | ||
|
||
plt.xlabel("Latency (nanoseconds)") | ||
#plt.ylabel("") | ||
plt.xscale('symlog') | ||
plt.tight_layout() | ||
plt.savefig('latency.png') | ||
plt.show() |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,28 @@ | ||
import sys | ||
import random | ||
|
||
# Argument parsing | ||
if len(sys.argv) != 2: | ||
print("Script expects 1 positive integer argument, %u found."%(len(sys.argv) - 1)) | ||
sys.exit() | ||
n = int(sys.argv[1]) | ||
# Init | ||
random.seed(12) | ||
arr = [random.random() for i in range(n)] | ||
print("Sorting %d elements"%(n)) | ||
# Sort | ||
for i in range(n - 1): | ||
swapped = False | ||
for j in range(0, n - i - 1): | ||
if arr[j] > arr[j + 1]: | ||
arr[j], arr[j + 1] = arr[j + 1], arr[j] | ||
swapped = True | ||
# If no two elements were swapped in the inner loop, the array is sorted | ||
if not swapped: | ||
break | ||
# Validate | ||
is_sorted = True | ||
for i in range(n - 1): | ||
if arr[i] > arr[i+1]: | ||
is_sorted = False | ||
print("Sorting: %s"%("Passed" if is_sorted else "Failed")) |
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,23 @@ | ||
n = 100 | ||
a=0 | ||
b=0 | ||
c=0 | ||
d=0 | ||
for i in range(1, n + 1): | ||
if i % 3 == 0 and i % 5 == 0: | ||
a+=1 | ||
print("FizzBuzz") | ||
elif i % 3 == 0: | ||
b+=1 | ||
print("Fizz") | ||
elif i % 5 == 0: | ||
c+=1 | ||
print("Buzz") | ||
else: | ||
d+=1 | ||
print(i) | ||
|
||
print(a) | ||
print(b) | ||
print(c) | ||
print(d) |
Oops, something went wrong.