ncmp

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
numcompare.py
A version of the module written using Python's string module.
regexpnumcompare.py
A version implemented using the re module.
ncmpmodule.c
A version written in C. Structurally, it mirrors numcompare.py exactly.

It is interesting to compare the speed of the three modules. For the kind of data I usually sort using this module, numcompare.py is about twice as quick, or rather half as slow, as regexpnumcompare.py. 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