[IronPython] CPython 25x faster than IronPython on this code

Chris Trimble trimbo at gmail.com
Wed Oct 12 18:51:37 CEST 2005


This same program in interpreted C# or Java (as opposed to JITed) runs
about the same speed as CPython (~110ms on my machine).  IronPython
takes almost 3 seconds in the inner loops.  Any ideas why?

IronPy version:
------------------------
import System

kTotalReps = 800
kNumReps = 100

start = System.Environment.TickCount
blah = 0
randgen = System.Random()
highnum = 0.0
for i in range(kTotalReps):
	myt = []
	for j in range(kNumReps):
		toadd = randgen.NextDouble()
		myt.append(toadd)
		highnum = max(highnum, toadd)
		blah = blah + 1

print blah
print highnum
print (System.Environment.TickCount-start)
----------------------


CPy version:
----------------------
import time
import random

kTotalReps = 800
kNumReps = 100

start = time.time()
blah = 0
highnum = 0.0
for i in range(kTotalReps):
	myt = []
	for j in range(kNumReps):
		toadd = random.random()
		myt.append(toadd)
		highnum = max(highnum, toadd)
		blah = blah + 1

print blah
print highnum
print (time.time()-start)*1000
-----------------------



More information about the Ironpython-users mailing list