Three different implementations of a modules which compares strings so that integer numerical substrings are compared according to their numerical values. E.g., given the following list: Sorting using ncmp instead of Python's cmp would result in the following list:
  1. ab1.9
  2. ab1.10
  3. ab9
  4. ab10
A version of the module written using Python's string module.
A version implemented using the re module.
A version written in C. Structurally, it mirrors exactly.

It is interesting to compare the speed of the three modules. For the kind of data I usually sort using this module, is about twice as quick, or rather half as slow, as The C version is of course very much quicker than both. The morale of the story being, as always, prototype in Python and reimplement the time consuming part in C. :)

Last updated 2000-05-04.

Steinar Knutsen