Skip to content

Commit 6d62867

Browse files
RobadobJostMigenda
andauthored
Reproduced jakevdp figures (#69)
* Reproduced int c vs py figure. Closes #62 * Reproduced numpy.array vs list figure. Closes #65 * Add jakevdp blog to acknowledgements. * v2 + alt array vs list * Update learners/acknowledgements.md Co-authored-by: Jost Migenda <[email protected]> * Fixup stroke width * Final version? * Fix stroke width * Increase stroke width to 1pt (from ~0.6) * White background Also upscaled int c vs py drawing --------- Co-authored-by: Jost Migenda <[email protected]>
1 parent f759130 commit 6d62867

File tree

7 files changed

+3388
-11
lines changed

7 files changed

+3388
-11
lines changed

episodes/fig/int-c-vs-py.ai

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

episodes/fig/int-c-vs-py.png

7.89 KB
Loading

episodes/fig/numpy-array-vs-list.ai

Lines changed: 1757 additions & 0 deletions
Large diffs are not rendered by default.
27.2 KB
Loading

episodes/optimisation-introduction.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,8 @@ This is not to say, don't consider performance when first writing code. The sele
5151
If you've read about different programming languages, you may have heard that there’s a difference between “interpreted” languages (like Python) and "compiled" languages (like C). You may have heard that Python is slow *because* it is an interpreted language.
5252
To understand where this comes from (and how to get around it), let's talk a little bit about how Python works.
5353

54-
<!--
55-
TODO: It might be nice to use the figure from https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/#1.-Python-is-Dynamically-Typed-rather-than-Statically-Typed. here for illustration?
56-
57-
![Illustration of integers in C and Python.](episodes/fig/cint_vs_pyint.png){alt="A diagram illustrating the difference between integers in C and Python. In C, the integer is a raw number in memory. In Python, it additionally contains a header with metadata."}
58-
-->
54+
![Illustration of integers in C and Python.](episodes/fig/int-c-vs-py.png){alt="A diagram illustrating the difference between integers in C and Python. In C, the integer is a raw number in memory. In Python, it additionally contains a header with metadata."}
55+
<!-- Figure inspired by https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/#1.-Python-is-Dynamically-Typed-rather-than-Statically-Typed. -->
5956

6057
In C, integers (or other basic types) are raw data in memory. It is up to the programmer to keep track of the data type.
6158
The compiler can then turn the source code directly into machine code. This allows the compiler to perform low-level optimisations that better exploit hardware nuance to achieve fast performance. This however comes at the cost of compiled software not being cross-platform.

episodes/optimisation-numpy.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,8 @@ Packages like NumPy and Pandas work similarly: They have been written in compile
3030

3131
It adds restriction via its own [basic numeric types](https://numpy.org/doc/stable/user/basics.types.html) and static arrays to enable even greater performance than that of core Python. However if these restrictions are ignored, the performance can become significantly worse.
3232

33-
<!--
34-
TODO: It might be nice to use the figure from https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/#3.-Python's-object-model-can-lead-to-inefficient-memory-access here for illustration?
35-
36-
![Illustration of a NumPy array and a Python list.](episodes/fig/numpyarray_vs_pylist.png){alt="A diagram illustrating the difference between a NumPy array and a Python list. The NumPy array is a raw block of memory containing numerical values. A Python list contains a header with metadata and multiple items, each of which is a reference to another Python object with its own header and value."}
37-
-->
33+
![Illustration of a NumPy array and a Python list.](episodes/fig/numpy-array-vs-list.png){alt="A diagram illustrating the difference between a NumPy array and a Python list. The NumPy array is a raw block of memory containing numerical values. A Python list contains a header with metadata and multiple items, each of which is a reference to another Python object with its own header and value."}
34+
<!-- Figure inspired by https://jakevdp.github.io/blog/2014/05/09/why-python-is-slow/#3.-Python's-object-model-can-lead-to-inefficient-memory-access -->
3835

3936
### NumPy Arrays and Python Lists Live in Two Separate Worlds
4037

learners/acknowledgements.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The development of this course was funded by the [University of Sheffield](https
88

99
**Authorship**
1010

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's [Research Software Engineering](https://rse.shef.ac.uk) and [Research IT](https://www.sheffield.ac.uk/it-services/research) teams.
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.
1212

1313
Additional consulting was provided by James Kilbane a close friend (and general rubber duck).
1414

@@ -18,3 +18,4 @@ Most of the content was drawn from the education and experience of the author, h
1818

1919
* [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).
2020
* [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).
21+
* [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.

0 commit comments

Comments
 (0)