I am just trying to compare the speed with matlab. The arrange is used for another test, that is why it shows up in the mail.

Thanks

Frank


From: "Marc 'BlackJack' Rintsch" <[EMAIL PROTECTED]>
To: python-list@python.org
Subject: Re: Speed of Python
Date: 7 Sep 2007 23:17:55 GMT

On Fri, 07 Sep 2007 22:59:26 +0000, wang frank wrote:

> I also have tried to use numpy to speed it up. However, surprisingly,
it is
> slower than the pure python code.
>
> Here is the code:
> import  numpy
> arange=numpy.arange
> nlog=numpy.log
> def bench6(n):
>    for i in xrange(n):
>            for j in xrange(1000):
>                    m=j+1
>                    z=nlog(m)
>                    z1=nlog(m+1)
>                    z2=nlog(m+2)
>                    z3=nlog(m+3)
>                    z4=nlog(m+4)
>                    z5=nlog(m+5)
>                    z6=nlog(m+6)
>                    z7=nlog(m+7)
>                    z8=nlog(m+8)
>                    z9=nlog(m+9)
>    return z9
>
> [窶ヲ]
>
> Anyone know why?

Because you don't really take advantage of `numpy`.  The `numpy.log()`
function can be used with scalars but I guess it is slower because it has
to check if its argument is a scalar or array.  Untested:

from numpy import arange, log as nlog

def bench6(n):
    for dummy in xrange(n):
        for j in xrange(1000):
            z = nlog(arange(j + 1, j + 11))
    return z[-1]
--
http://mail.python.org/mailman/listinfo/python-list

_________________________________________________________________
3つの”ホンモノ”プレゼント 賞品第3弾スタート!アルファ スパイダー2.2が当た
http://clk.atdmt.com/GBL/go/msnjpqjl0060000010gbl/direct/01/
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to