numpy/numpy — pull request #3779 by pv (2013-09-22 18:00:58+00:00)
Title: ENH: core: add a fast path for PEP3118 buffer string parsing

The parsing of PEP 3118 format strings is currently written in Python, and this is somewhat slow. The call back to Python numpy.core._internal._dtype_from_pep3118 is an unnecessary large overhead for the most common case, when the buffer passed in has a simple non-composite type.

This is annoying especially for Cython, whose otherwise nice memoryview syntax takes a hit from this overhead when small arrays are used.

This PR adds a fast path for the simple case.

Before:
```
In [2]: %%cython
...: import numpy as np
...: def nop(double[::1] arr):
...: return np.asarray(arr)
...:

In [3]: x = randn(1000000)

In [4]: %timeit nop(x)
100000 loops, best of 3: 15.3 us per loop

In [5]: y = memoryview(x)

In [6]: %timeit np.asarray(y)
100000 loops, best of 3: 12.8 us per loop
```
After:
```
In [2]: %%cython
...: import numpy as np
...: def nop(double[::1] arr):
...: return np.asarray(arr)
...:

In [3]: x = randn(1000000)

In [4]: %timeit nop(x)
100000 loops, best of 3: 2.73 us per loop

In [5]: y = memoryview(x)

In [6]: %timeit np.asarray(y)
1000000 loops, best of 3: 1.24 us per loop
```