pytoolz/cytoolz — pull request #44 by eriknw (2014-07-02 15:43:24+00:00)
Title: Faster join by using subclasses for each case (type of join and index keys)

This is not the cleanest way to handle multiple key types (callable, list of indices, and a single index), and I don't want the current approach to set a precedence that will be used by other classes. A cleaner approach would be to have a single `make_key` function with the following signature:
```python
cdef inline object make_key(object rightkey, object item,
bint iscallable, bint islist)
```
I doubt that using `make_key` would significantly impact the performance.

But, the current implementation is written, works, and is fast, and I'm not one to reject code that meets those criteria.

I adapted the benchmarks from "toolz/bench/test_join.py" to `benchtoolz`. "old" is the previous implementation, "new" is the current implementation, and "inline" is the new implementation with a bunch of copy-paste to perform the key calculation with no method call or indirection ("new" doesn't inline, but "cdef" functions are pretty fast; function pointers are used under the hood).

**Time:**

| __Bench__ \ __Func__ | ___inline__ | ___new__ | ___old__ |
| -------------------------------------:|:-----------:|:---------:|:--------:|
| __many_to_many_large__ (`s`) | *1.02* | __0.987__ | 1.41 |
| __many_to_many_small__ (`ms`) | *1.46* | __1.45__ | 1.87 |
| __many_to_many_small_index__ (`ms`) | __0.91__ | *0.914* | 1.45 |
| __many_to_many_small_indices__ (`ms`) | *1.33* | __1.32__ | 1.94 |
| __one_to_many__ (`ms`) | __6.84__ | *7.13* | 10.8 |
| __one_to_one_tiny__ (`us`) | __18.5__ | *19* | 24.5 |

**Relative time:**

| __Bench__ \ __Func__ | ___inline__ | ___new__ | ___old__ |
| ------------------------------:|:-----------:|:--------:|:--------:|
| __many_to_many_large__ | *1.03* | __1__ | 1.43 |
| __many_to_many_small__ | *1.01* | __1__ | 1.3 |
| __many_to_many_small_index__ | __1__ | *1* | 1.59 |
| __many_to_many_small_indices__ | *1* | __1__ | 1.46 |
| __one_to_many__ | __1__ | *1.04* | 1.59 |
| __one_to_one_tiny__ | __1__ | *1.02* | 1.32 |