[IronPython] Nice speed

Travis Watkins alleykat at gmail.com
Wed Apr 27 02:21:54 CEST 2005


On 4/26/05, Michael Spencer <mahs at telcopartners.com> wrote:
> IronPython runs this sieve function 20-30% faster than CPython
> 
> def primes2(n):
>      if n<2: return []
>      s=range(1,n,2) # [1,3,5....n | n-1]
>      s[0] = 2
>      len_s = len(s)
>      for i in xrange(1,int(sqrt(n)/2)+1):
>          m = s[i]
>          if m:
>              j=(m*m)/2
>              while j<len_s:
>                  s[j]=0
>                  j = j+m
> 
>      return [i for i in s if i]
> 
> def timeit(N):
>      t1 = time.clock()
>      l1 = primes2(N)
>      tp1 = time.clock()- t1
>      return tp1
> 
> CPython 2.4
>   >>> [timeit(1000000) for i in 1,2,3]
>   [0.746761948795168, 0.76873792618893333, 0.78001002920763085]
>   >>>
> 
> IronPython 0.7.3
>   >>> [timeit(1000000) for i in 1,2,3]
>   [0.590843200683594, 0.550788879394531, 0.490707397460938]
>   >>>
> 
> Michael
> 
> _______________________________________________
> users-ironpython.com mailing list
> users-ironpython.com at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> 

Never trust the program you're running to give you accurate time. Use
'time python foo.py' instead. If you're going to do that put most of
the code in a seperate file that gets imported so the bytecode gets
cached since IronPython is precompiled to IL. Other than that, cool.

-- 
Travis Watkins
http://www.realistanew.com



More information about the Ironpython-users mailing list