Blog of Julian Andres Klode

April 29, 2008

Python Speed: ‘x in list’ vs ‘x in set’

Filed under: Python — Julian Andres Klode @ 19:42

Well, this is my second post about speed in Python. Today, I noticed that debimg’s dependency resolver was much much slower than before. I thought what the problem could be and finally realized that the problem was that I switched from sets to list. This is fixed now in commit d0fd700080de5c19cb5fd66918d14c5ffa26e805

Now, some benchmarks (using IPython):

In [1]: a = range(10**6)

In [2]: b = set(a)

In [3]: %timeit 10**6 in a
10 loops, best of 3: 31.8 ms per loop

In [4]: %timeit 10**6 in b
10000000 loops, best of 3: 98.6 ns per loop

1ms are 1 million ns. Therefore, using sets is about 322515 times faster than using lists (or tuples).

debimg can now calculate dependencies in 0.5 seconds again, instead of 1 minute with lists.

April 17, 2008

python-libisofs 0.0.1 available

Filed under: Debian, General, Python, Ubuntu — Julian Andres Klode @ 17:37

A first preview of the python-libisofs bindings is available now. It’s currently located in a git branch at git.debian.org, but this may change at a later point.

The bindings support the creation of ISO Images and (almost) all options libisofs supports, like Rockridge, Joliet, and much more. Reading and Modifying existing images is not supported yet.

The code is written in Cython and you need cython installed for building from the git branch. It can be installed just like any other Python module/extension/package, using a setup.py.

Browse: http://git.debian.org/?p=users/jak-guest/python-libisofs.git
Get: git clone git://git.debian.org/git/users/jak-guest/python-libisofs.git

I’ll package it for Debian within the next weeks after some further tests.

April 2, 2008

Python Extension for libisofs

Filed under: Debian, Python — Julian Andres Klode @ 18:33

I am working on a Python extension for the libisofs library. The extension is written in Cython , a Python-like language designed to write Python extensions.

At a later point, this extension will be used to create the ISO Images in debimg. It will be disabled by default, but you can enable it via a configuration option.

March 24, 2008

Python Speed: Getting the first part of a string

Filed under: Python — Julian Andres Klode @ 23:38

If you want to get the first part of a string (in the following example a), you should use the partition method of the string, as it is the fastest way (and it also gives you the delimiter in [1] and the other part of the string in [2]):

In [1]: a = ‘a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z’

In [2]: timeit a.partition(’/')[0]
1000000 loops, best of 3: 362 ns per loop

In [3]: timeit a[:a.find('/')]
1000000 loops, best of 3: 443 ns per loop

In [4]: timeit a.split(’/', 1)[0]
1000000 loops, best of 3: 697 ns per loop

In [5]: timeit a.split(’/')[0]
1000000 loops, best of 3: 1.45 µs per loop

These tests were made with IPython 0.8.1 (Python 2.5.1 (r251:54863, Oct 5 2007, 13:50:07) ) on an Ubuntu 64 bit system.

Older Posts »

Blog at WordPress.com.