pytoolz/cytoolz — pull request #18 by larsmans (2014-05-01 17:30:18+00:00)
Title: dicttoolz.pyx: faster iteration over dicts (10% speedup for keymap and friends)

This speeds up several operations in `dicttoolz.pyx` by using `PyDict_Next` instead of a Cython loop over the `iteritems`. Using the example predicate for `keyfilter`, I got the following results. Before:

```
>>> iseven = lambda x: x % 2 == 0
>>> d = dict(enumerate(range(1, 25000)))
>>> %timeit keyfilter(iseven, d)
100 loops, best of 3: 3.19 ms per loop
```

After:

```python
>>> %timeit keyfilter(iseven, d)
100 loops, best of 3: 2.85 ms per loop
```

I tried to apply the recipe to `c_merge_with` but found no difference in performance with large dicts, nor with a combination of large and small dicts, so I concluded that dict iteration isn't the bottleneck there (while the code became a lot more complicated). I did not try the many dicts use case.