This page list all efforts to make Hachoir faster.

Benchmark with benchmark.sh shell

To run the benchmark, use:

./benchmark.sh

Data on haypo's computer with Python 2.4.3

hachoir-grep on testcase/yellowdude.3ds:

  • svn 1058: 1.05 ms
  • svn 807: 1.05 sec
  • svn 769: 1.09 sec
  • svn 681: 1.22 sec
  • svn 610: 1.20 sec

hachoir-metadata: set A (mp3, wav, png, au, mkv):

  • svn 1058: 324.3 ms
  • svn 807: 153.4 ms

Benchmark using program time command

Are this mesure really usefull? :-p

time python -OO script/hachoir-metadata testcase/logo-Kubuntu.png (smallest value of "real"):

  • svn 807: 185 ms
  • svn 769: 173 ms
  • svn 681: 172 ms
  • svn 610: 190 ms
  • svn 508: 170 ms
  • svn 479: 105 ms
  • 2006-07-19: 260 ms
  • version 0.3: 380 ms

Tricks

Faster Class.__init__

class Classic:
  def __init__(self):
     self._x = 0
     self._y = {}
     self._z = 4

class Faster:
  _x = 0
  _z = 4
  def __init__(self):
     self._y = {} # you can't move it !

Mutable (list, dict, etc.) can't be moved outside __init__().

function calling

Call a function is slow (at least in CPython), so use less function call as possible.

You can use "inlining":

def useless(a, b):
   print "a=%s b=%s" % (a, b):

def slow(a):
   b = a*2
   useless(a, b)
--
def fast(a):
   b = a*2
   print "a=%s b=%s" % (a, b):

Comparaison

  • "if hasattr()" is slower than "if value is not None"
  • "if x != None" is slower than "if x is not None"

Links

Articles:

Tools:

  • pyrex: new language mixing Python and C types
  • psyco: Just In Time (only for i386) for Python
  • PyInline, weave: add C "script" in your Python source
  • py2cmod: Tool to convert Python to C