numpy.empty 1800x slower than CPython; numpy.zeros 10x slower
Created originally on Bitbucket by Crusader Ky (crusaderky)
numpy.empty currently zeros out the memory in pypy. In cpython, it obviously doesn't. There's a lot of situations I can think of where you don't care about memory initialisation, e.g. when you're allocating the memory for a C or OpenCL function to write to.
On very small arrays, pypy is faster than cpython:
timeit('np.empty((5,), dtype=np.float64)', setup='import numpy as np', number=1000000) CPython: 0.48946094512939453 PyPy: 0.21847295761108398
timeit('np.zeros((5,), dtype=np.float64)', setup='import numpy as np', number=1000000) CPython: 0.4740109443664551 PyPy: 0.20502209663391113
On large ones (4MB), however, CPython wins by a large gulf:
timeit('np.empty((500000,), dtype=np.float64)', setup='import numpy as np', number=1000) CPython: 0.000637054443359375 PyPY: 1.1482269763946533 (1800x slower)
timeit('np.zeros((500000,), dtype=np.float64)', setup='import numpy as np', number=1000) CPython: 0.13871288299560547 PyPy: 1.2538270950317383 (10x slower)
Tests run on CPython 2.7.6 + numpy-1.8.1 vs pypy-c-jit-71909-2d96616d4fd6-linux64 + latest numpy fork from git.