benhoyt/scandir — pull request #2 by dholth (2013-05-15 02:34:49+00:00)
Title: A cffi version

Here's a cffi version using dlopen. Might modify it to use verify() so that the C compiler helps us out a little more.

Check it out:

```
(pypy20)dholth@cardamom:~/var/pypy20/src/scandir$ python benchmark.py
Priming the system's cache...
Benchmarking walks on benchtree, repeat 1/3...
Benchmarking walks on benchtree, repeat 2/3...
Benchmarking walks on benchtree, repeat 3/3...
os.walk took 0.136s, scandir.walk took 0.120s -- 1.1x as fast
(pypy20)dholth@cardamom:~/var/pypy20/src/scandir$ rm _scandir.
_scandir.c _scandir.c~ _scandir.pypy-20.so
(pypy20)dholth@cardamom:~/var/pypy20/src/scandir$ rm _scandir.pypy-20.so
(pypy20)dholth@cardamom:~/var/pypy20/src/scandir$ python benchmark.py
/home/dholth/var/pypy20/src/scandir/scandir.py:340: UserWarning: Using slow Python version of scandir(), please build _scandir.c using setup.py
warnings.warn('Using slow Python version of scandir(), please build _scandir.c using setup.py')
Priming the system's cache...
Benchmarking walks on benchtree, repeat 1/3...
Benchmarking walks on benchtree, repeat 2/3...
Benchmarking walks on benchtree, repeat 3/3...
os.walk took 0.137s, scandir.walk took 0.042s -- 3.3x as fast
```

But on CPython 2.7:

```
(py27)dholth@cardamom:~/var/pypy20/src/scandir$ python benchmark.py
Priming the system's cache...
Benchmarking walks on benchtree, repeat 1/3...
Benchmarking walks on benchtree, repeat 2/3...
Benchmarking walks on benchtree, repeat 3/3...
os.walk took 0.119s, scandir.walk took 0.041s -- 2.9x as fast
(py27)dholth@cardamom:~/var/pypy20/src/scandir$ rm _scandir.so
(py27)dholth@cardamom:~/var/pypy20/src/scandir$ python benchmark.py
/home/dholth/var/pypy20/src/scandir/scandir.py:340: UserWarning: Using slow Python version of scandir(), please build _scandir.c using setup.py
warnings.warn('Using slow Python version of scandir(), please build _scandir.c using setup.py')
Priming the system's cache...
Benchmarking walks on benchtree, repeat 1/3...
Benchmarking walks on benchtree, repeat 2/3...
Benchmarking walks on benchtree, repeat 3/3...
os.walk took 0.123s, scandir.walk took 0.086s -- 1.4x as fast
```