kislyuk/ensure — pull request #5 by harrisonmetz (2014-06-15 23:17:41+00:00)
Title: Further optimize ensure annotations

The wrapper can be further optimized. This new change stores each arg name, template, and position together. This eliminates the 'return' map lookup each iteration, avoids the kwargs map lookup check if it was positional, and eliminates the arg to pos map lookup as well.

Microbenchmark:

Before:
Mean 3.297391904052347 us
Min 2.9989751055836678 us
Max 31.033996492624283 us
stdev 5.870001651992793e-07

After:
Mean 2.516213699709624 us
Min 2.249958924949169 us
Max 21.4350875467062 us
stdev 5.480925631868802e-07

Unit tests pass, as well as a program using this. I believe this works (and I think it simplifies the logic too), will think about it more, but pretty sure this should do it.