[IronPython] IronPython vs Cpython import speeds.

Dino Viehland dinov at exchange.microsoft.com
Mon Jan 8 15:13:51 PST 2007

Unfortunately import speed is one of the areas where CPython is drastically faster than IronPython.  The primary reason for this is that we will compile all the modules that get imported during importation which slows things down.

One possible work around is to use the pyc tutorial although that's known to not work with packages.  Also you can vote on this bug (http://www.codeplex.com/IronPython/WorkItem/View.aspx?WorkItemId=358) which will enable us caching the modules on disk (like CPython caches .pyc files) so that import time will be greatly improved.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of illium
Sent: Monday, January 08, 2007 2:35 PM
To: users at lists.ironpython.com
Subject: [IronPython] IronPython vs Cpython import speeds.


I'm in the process of porting a project from CPython
to IronPython. This is my first time using IronPython,
so I'm not completely sure what to expect.

After getting over the inital configuration hurdles, I
got my program to execute normally within IronPython,
and moved on to performance testing, attempting to
feel all warm and fuzzy about how much faster my code
was running in shiny new IronPtyhon. However, I
immediately noticed a major difference, to the worse,
in speed performance between the two engines.

In order to isolate the problem I started adding time
stamp traces into the code, and found that the
majority of the perfomance loss was occuring during
import calls.

So I made this little test file, importspeedtest.py:

import time
print time.time()
import sys, os, string, re
print time.time()

Then made this little batch file to compare them...

@echo IronPython
@echo ----------
@echo %time%
@echo %time%
@echo ----------
@echo Python 2.5
@echo ----------
@echo %time%
@echo %time%
@echo ----------

The results:

Python 2.5

The total execution time in IronPython was 2.64
seconds, and in CPython was .09 seconds.

The amount of time to execute the line "import sys,
os, string, re" in IronPython was 1.2 seconds, and in
CPython .01 seconds.

In actual use in my project I found that start to
finish, with the overhead of launching the embedded
engine, loading and executeing the source file, doing
the processing on my sample data, and exiting, using
IronPython it took 5 seconds, with 2 seconds of that
time being the import calls, while the same
process/code using Python 2.5 completed in only 1.5
seconds round trip, with .02 seconds used for the
import calls.

So.. on to my question:

Is this normal, or am I doing something wrong? Is
there  a way to optimize my code for faster loading in

Any assistance/insight would be greatly appreciated,
as I really want to move over to IronPython, so that I
can embedd it into my c# app, instead of calling it
via the commandline as I'm currently doing with
CPython. But this kind of performance loss makes it
unusable at the moment.

Troy Howard

Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
users mailing list
users at lists.ironpython.com

More information about the users mailing list