Skip to content

Commit bdbdc69

Browse files
committed
source commit: bf03b53
0 parents  commit bdbdc69

File tree

79 files changed

+19388
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+19388
-0
lines changed

CODE_OF_CONDUCT.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
title: "Contributor Code of Conduct"
3+
---
4+
5+
As contributors and maintainers of this project,
6+
we pledge to follow the [The Carpentries Code of Conduct][coc].
7+
8+
Instances of abusive, harassing, or otherwise unacceptable behavior
9+
may be reported by following our [reporting guidelines][coc-reporting].
10+
11+
12+
[coc-reporting]: https://docs.carpentries.org/topic_folders/policies/incident-reporting.html
13+
[coc]: https://docs.carpentries.org/topic_folders/policies/code-of-conduct.html

LICENSE.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
title: "Licenses"
3+
---
4+
5+
## Instructional Material
6+
7+
All Carpentries (Software Carpentry, Data Carpentry, and Library Carpentry)
8+
instructional material is made available under the [Creative Commons
9+
Attribution license][cc-by-human]. The following is a human-readable summary of
10+
(and not a substitute for) the [full legal text of the CC BY 4.0
11+
license][cc-by-legal].
12+
13+
You are free:
14+
15+
- to **Share**---copy and redistribute the material in any medium or format
16+
- to **Adapt**---remix, transform, and build upon the material
17+
18+
for any purpose, even commercially.
19+
20+
The licensor cannot revoke these freedoms as long as you follow the license
21+
terms.
22+
23+
Under the following terms:
24+
25+
- **Attribution**---You must give appropriate credit (mentioning that your work
26+
is derived from work that is Copyright (c) The Carpentries and, where
27+
practical, linking to <https://carpentries.org/>), provide a [link to the
28+
license][cc-by-human], and indicate if changes were made. You may do so in
29+
any reasonable manner, but not in any way that suggests the licensor endorses
30+
you or your use.
31+
32+
- **No additional restrictions**---You may not apply legal terms or
33+
technological measures that legally restrict others from doing anything the
34+
license permits. With the understanding that:
35+
36+
Notices:
37+
38+
* You do not have to comply with the license for elements of the material in
39+
the public domain or where your use is permitted by an applicable exception
40+
or limitation.
41+
* No warranties are given. The license may not give you all of the permissions
42+
necessary for your intended use. For example, other rights such as publicity,
43+
privacy, or moral rights may limit how you use the material.
44+
45+
## Software
46+
47+
Except where otherwise noted, the example programs and other software provided
48+
by The Carpentries are made available under the [OSI][osi]-approved [MIT
49+
license][mit-license].
50+
51+
Permission is hereby granted, free of charge, to any person obtaining a copy of
52+
this software and associated documentation files (the "Software"), to deal in
53+
the Software without restriction, including without limitation the rights to
54+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
55+
of the Software, and to permit persons to whom the Software is furnished to do
56+
so, subject to the following conditions:
57+
58+
The above copyright notice and this permission notice shall be included in all
59+
copies or substantial portions of the Software.
60+
61+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
67+
SOFTWARE.
68+
69+
## Trademark
70+
71+
"The Carpentries", "Software Carpentry", "Data Carpentry", and "Library
72+
Carpentry" and their respective logos are registered trademarks of [Community
73+
Initiatives][ci].
74+
75+
[cc-by-human]: https://creativecommons.org/licenses/by/4.0/
76+
[cc-by-legal]: https://creativecommons.org/licenses/by/4.0/legalcode
77+
[mit-license]: https://opensource.org/licenses/mit-license.html
78+
[ci]: https://communityin.org/
79+
[osi]: https://opensource.org

acknowledgements.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Acknowledgements
3+
---
4+
5+
**Funding**
6+
7+
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.
8+
9+
**Authorship**
10+
11+
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 of Sheffield's [Research Software Engineering](https://rse.shef.ac.uk) and [Research IT](https://www.sheffield.ac.uk/it-services/research) teams.
12+
Additional consulting was provided by James Kilbane, a close friend (and general rubber duck).
13+
14+
[Jost Migenda](https://www.kcl.ac.uk/people/jost-migenda) from the [KCL e-Research department](https://www.kcl.ac.uk/research/facilities/e-research) contributed significant improvements and additions to the optimization episodes. They have also become a co-maintainer of the course.
15+
16+
Anastasiia Shcherbakova and Mira Sarkis of [ICR-RSE](https://github.com/ICR-RSE-Group) contributed inspiration for the list append figure and a large number of typographic corrections and simplifications during the alpha phase of the course's development lifecycle.
17+
18+
**Resources**
19+
20+
Most of the content was drawn from the education and experience of the authors, however the below resources provided inspiration:
21+
22+
* [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-latency.html#memory-allocation-is-not-free) and [vectorisation](optimisation-latency.html#memory-allocation-is-not-free).
23+
* [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 [latency episode](optimisation-latency).
24+
* [Why Python is Slow: Looking Under the Hood](https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/): This blog post looks under the hood of CPython to explain why Python is often slower than C (and NumPy). We reproduced two of its figures in the [optimisation introduction](optimisation-introduction.html) and [numpy](optimisation-numpy) episodes to explain how memory is laid out.

config.yaml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#------------------------------------------------------------
2+
# Values for this lesson.
3+
#------------------------------------------------------------
4+
5+
# Which carpentry is this (swc, dc, lc, or cp)?
6+
# swc: Software Carpentry
7+
# dc: Data Carpentry
8+
# lc: Library Carpentry
9+
# cp: Carpentries (to use for instructor training for instance)
10+
# incubator: The Carpentries Incubator
11+
carpentry: 'incubator'
12+
13+
# Overall title for pages.
14+
title: 'Performance Profiling & Optimisation (Python)'
15+
16+
# Date the lesson was created (YYYY-MM-DD, this is empty by default)
17+
created: 2024-02-01~ # FIXME
18+
19+
# Comma-separated list of keywords for the lesson
20+
keywords: 'python, profiling, optimisation, data structures, algorithms'
21+
22+
# Life cycle stage of the lesson
23+
# possible values: pre-alpha, alpha, beta, stable
24+
life_cycle: 'beta'
25+
26+
# License of the lesson
27+
license: 'CC-BY 4.0'
28+
29+
# Link to the source repository for this lesson
30+
source: 'https://github.com/carpentries-incubator/pando-python'
31+
32+
# Default branch of your lesson
33+
branch: 'main'
34+
35+
# Who to contact if there are any issues
36+
37+
38+
# Navigation ------------------------------------------------
39+
#
40+
# Use the following menu items to specify the order of
41+
# individual pages in each dropdown section. Leave blank to
42+
# include all pages in the folder.
43+
#
44+
# Example -------------
45+
#
46+
# episodes:
47+
# - introduction.md
48+
# - first-steps.md
49+
#
50+
# learners:
51+
# - setup.md
52+
#
53+
# instructors:
54+
# - instructor-notes.md
55+
#
56+
# profiles:
57+
# - one-learner.md
58+
# - another-learner.md
59+
60+
# Order of episodes in your lesson
61+
episodes:
62+
- profiling-introduction.md
63+
- profiling-functions.md
64+
- short-break1.md
65+
- profiling-lines.md
66+
- profiling-conclusion.md
67+
- optimisation-introduction.md
68+
- optimisation-using-python.md
69+
- optimisation-data-structures-algorithms.md
70+
- long-break1.md
71+
- optimisation-numpy.md
72+
- optimisation-use-latest.md
73+
- optimisation-latency.md
74+
- optimisation-conclusion.md
75+
76+
# Information for Learners
77+
learners:
78+
- setup.md
79+
# - registration.md # University of Sheffield specific registration procedure
80+
- technical-appendix.md
81+
- acknowledgements.md
82+
- ppp.md
83+
- reference.md
84+
85+
# Information for Instructors
86+
instructors:
87+
88+
# Learner Profiles
89+
profiles:
90+
91+
# Customisation ---------------------------------------------
92+
#
93+
# This space below is where custom yaml items (e.g. pinning
94+
# sandpaper and varnish versions) should live
95+
96+
# These config items are used to deploy the University of Sheffield varnish theme
97+
#varnish: RSE-Sheffield/uos-varnish@main
98+
#url: 'https://rse.shef.ac.uk/pando-python'
99+
100+
analytics: |
101+
<script defer src="https://cloud.umami.is/script.js" data-website-id="2b561bd0-0d7a-436b-a18d-d19c94785362"></script>

fig/annotated-motherboard.jpg

407 KB
Loading

fig/bookshelf_dict.jpg

288 KB
Loading

fig/bookshelf_list.jpg

119 KB
Loading

fig/cpython_list_allocations.png

14.3 KB
Loading

fig/cpython_list_allocations.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""
2+
Construct a graph demonstrating the number of re-allocations
3+
if growing a CPython List with append()
4+
"""
5+
t = 0
6+
a = 0
7+
x = range(1000000)
8+
9+
allocs = [0 for x in range(1000000)]
10+
while t < 1000000:
11+
t += 1
12+
t_old = t
13+
# https://github.com/python/cpython/blob/a571a2fd3fdaeafdfd71f3d80ed5a3b22b63d0f7/Objects/listobject.c#L74
14+
t = t + (t >> 3) + 6
15+
a+=1
16+
for k in range(t_old, t+1):
17+
if k < len(allocs):
18+
allocs[k] = a
19+
20+
import matplotlib.pyplot as plt
21+
22+
plt.plot(x, allocs)
23+
24+
plt.xlabel("Appends")
25+
plt.ylabel("Resizes")
26+
#plt.ticklabel_format(style='plain')
27+
#plt.xscale('symlog')
28+
plt.savefig('cpython_list_allocations.png')
29+
plt.show()

fig/hardware.ai

Lines changed: 1540 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)