Cythonize!

In this post I take Python code to do a task (draw fractals), write it in the spirit of Python (a pleasure to write, read and maintain), use profiling to figure out the bottle necks and then speed up the most time consuming function using cython. Python is great for writing projects of all sizes.… Read More Cythonize!

numpy and testing

Numpy has some great builtins for running unit tests under numpy.testing . There are routines for comparing arrays that come in handy for tests. Many of these have verbose settings that give useful details in a thoughtful format for chasing down why a test failed.

Use numpydoc + sphinx

An ideal code documentation system should allow you to write documentation once (when you are writing the code) and then allow you to display the documentation in different contexts, such as project manuals, inline help, command line help and so on. You shouldn’t need to duplicate docs – it is a waste of effort and… Read More Use numpydoc + sphinx

Recap: Python list indexing is O(1)

Just in case any of you, hearing about how slow and ponderous Python is, were worried about indexing into a list – it’s a O(1) operation: In [936]: big_list = range(int(1e8))len(bIn [937]: len(big_list)Out[937]: 100000000In [938]: %timeint big_list[-1]ERROR: Line magic function `%timeint` not found.In [939]: %timeit big_list[-1]10000000 loops, best of 3: 66.1 ns per loopIn [940]:… Read More Recap: Python list indexing is O(1)

Python string concatenation

Continuing with our timing and efficiency theme: What is the more efficient way of building up a string? from cStringIO import StringIOdef string_concat(size=int(1e6)): repeat = ‘A’ st = ” for n in range(size): st += repeat return stdef list_concat(size=int(1e6)): repeat = ‘A’ st = [] for n in range(size): st += repeat return ”.join(st)def stringIO_concat(size=int(1e6)):… Read More Python string concatenation