[Numpy-discussion] strange sin/cos performance
Emmanuelle Gouillart
emmanuelle.gouillart@normalesup....
Mon Aug 3 08:45:56 CDT 2009
Hi Andrew,
%timeit is an Ipython magic command that uses the timeit module,
see
http://ipython.scipy.org/doc/stable/html/interactive/reference.html?highlight=timeit
for more information about how to use it. So you were right to suppose
that it is not a "normal Python".
However, I was not able to reproduce your observations.
>>> import numpy as np
>>> a = np.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=np.float32)
>>> b = np.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=np.float64)
>>> %timeit -n 10 np.sin(a)
10 loops, best of 3: 8.67 ms per loop
>>> %timeit -n 10 np.sin(b)
10 loops, best of 3: 9.29 ms per loop
Emmanuelle
On Mon, Aug 03, 2009 at 09:32:57AM -0400, Andrew Friedley wrote:
> While working on GSoC stuff I came across this weird performance
> behavior for sine and cosine -- using float32 is way slower than
> float64. On a 2ghz opteron:
>
> sin float32 1.12447786331
> sin float64 0.133481025696
> cos float32 1.14155912399
> cos float64 0.131420135498
>
> The times are in seconds, and are best of three runs of ten iterations
> of numpy.{sin,cos} over a 1000-element array (script attached). I've
> produced similar results on a PS3 system also. The opteron is running
> Python 2.6.1 and NumPy 1.3.0, while the PS3 has Python 2.5.1 and NumPy
> 1.1.1.
>
> I haven't jumped into the code yet, but does anyone know why sin/cos are
> ~8.5x slower for 32-bit floats compared to 64-bit doubles?
>
> Side question: I see people in emails writing things like 'timeit
> foo(x)' and having it run some sort of standard benchmark, how exactly
> do I do that? Is that some environment other than a normal Python?
>
> Thanks,
>
> Andrew
> import timeit
> t = timeit.Timer("numpy.sin(a)",
> "import numpy\n"
> "a = numpy.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=numpy.float32)")
> print "sin float32", min(t.repeat(3, 10))
> t = timeit.Timer("numpy.sin(a)",
> "import numpy\n"
> "a = numpy.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=numpy.float64)")
> print "sin float64", min(t.repeat(3, 10))
> t = timeit.Timer("numpy.cos(a)",
> "import numpy\n"
> "a = numpy.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=numpy.float32)")
> print "cos float32", min(t.repeat(3, 10))
> t = timeit.Timer("numpy.cos(a)",
> "import numpy\n"
> "a = numpy.arange(0.0, 1000, (2 * 3.14159) / 1000, dtype=numpy.float64)")
> print "cos float64", min(t.repeat(3, 10))
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list