Skip to content

Commit

Permalink
source commit: 1a4e1f4
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Mar 22, 2024
0 parents commit 39c15ab
Show file tree
Hide file tree
Showing 58 changed files with 13,278 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CODE_OF_CONDUCT.md
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
79 changes: 79 additions & 0 deletions LICENSE.md
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
20 changes: 20 additions & 0 deletions acknowledgements.md
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).
90 changes: 90 additions & 0 deletions config.yaml
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'
Binary file added fig/annotated-motherboard.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/cpython_list_allocations.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions fig/cpython_list_allocations.py
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()
1,540 changes: 1,540 additions & 0 deletions fig/hardware.ai

Large diffs are not rendered by default.

Binary file added fig/hardware.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,341 changes: 2,341 additions & 0 deletions fig/hash_linear_probe.ai

Large diffs are not rendered by default.

Binary file added fig/hash_linear_probing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/latency.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions fig/latency.py
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", "Atlantic round trip"]
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()
Binary file added fig/line_profiler-worked-example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/pando-python-hex-sticker.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/predprey_out.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/snakeviz-home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/snakeviz-predprey-table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/snakeviz-worked-example-icicle.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fig/snakeviz-worked-example-sunburst.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 39c15ab

Please sign in to comment.