numpy/numpy — pull request #3686 by arinkverma (2013-09-04 23:49:03+00:00)
Title: ENH: High time consumption by PyUFunc_GetPyValues in ufunc_object.c

For every single operation calls, numpy has to extract value of buffersize, errormask and name to pack and build error object. These two functions, _extract_pyvals and PyUFunc_GetPyValues together use >12% of time. it take useless time because all this time is spent on to look up entries in a python dict, extract them, and convert them into C level data. Not once but doing that again and again on every operation.

Here, I stash value to thread using TLS api and also avoiding building of errorObj again for same consecutive function.

## Improvement
### Before

In [1]: import numpy as np

In [2]: x = np.asarray(1)

In [3]: timeit x+x
1000000 loops, best of 3: 1.73 us per loop

In [4]: x = np.asarray([1])

In [5]: timeit x+x
100000 loops, best of 3: 1.79 us per loop

### After

In [1]: import numpy as np

In [2]: x = np.asarray(1)

In [3]: timeit x+x
1000000 loops, best of 3: 1.62 us per loop

In [4]: x = np.asarray([1])

In [5]: timeit x+x
1000000 loops, best of 3: 1.69 us per loop