Slower Than Expected

This post originally appeared on the Software Carpentry website.

We've started work on the high-performance computing lecture, and as part of that, we'd like to set a puzzle for our more advanced readers. We've written several versions of invasion percolation; the two of interest here use a list-based representation for the underlying grid, and a NumPy array. Run either program as:

python -g -n 31 -v 100

-g turns off the end-of-run graphical display; -n 31 tells the program to use a 31×31 grid; and -v 100 tells it to initialize cells to random values between 0 and 100. Try varying the size, compare the speeds of the two programs, see if you can figure out why one is faster than the other, and then tell us:

  1. what you found, and
  2. how you found it.

#2 is actually more important to us than #1, since we'd like to figure out how programmers actually go about diagnosing performance problems. Please post your findings as comment on this blog after Wednesday, Jan 12 (to give everyone else a chance to try it out too).

Update: WordPress seems to "fix" indentation (leading white space) more or less randomly when I paste code into a <pre> area, so I'll link to the two files.

Using Lists

Using NumPy

[Later version of lecture on invasion percolation]

Dialogue & Discussion

Comments must follow our Code of Conduct.

Edit this page on Github