[IronPython] Nice speed

Michael Spencer mahs at telcopartners.com
Wed Apr 27 01:37:06 CEST 2005


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




More information about the Ironpython-users mailing list