[IronPython] ScriptScope.SetVariable() performance

Cory Brostowicz cory.brostowicz at gmail.com
Thu Aug 12 16:34:22 CEST 2010


I'm trying to get more performance out of my IronPython scripts inside one
of my applications, and noticed I'm spending the bulk of my time setting up
the ScriptScope prior to execution.  My applications translates information
coming from a flat file, and I use IronPython to enforce business rules on
various records that I pull from my input file.  The object that I'm passing
to the scope is custom implementation of the ExpandoObject.

Am I doing anything out of the ordinary here, or is there a better way to
get the performance I'm after?  It doesn't seem like setting up the script
should performance significantly slower than executing the script itself.

Here is an example of the performance results I'm getting.  I'm keeping
track of various timings for execution time, but the script setup timer is
really just stopping and starting a stopwatch before and after each call to


Edit: SetProviderType           Count: 70291   Min: 9.927000E-001 Max:
4.922160E+001 Total: 7.656987E+004 Setup: 4.667084E+005
Edit: SetFeeSchedule            Count: 70291   Min: 1.572500E+000 Max:
6.547200E+001 Total: 1.067754E+005 Setup: 4.639014E+005
Edit: phDefaultNetworkCode      Count: 70291   Min: 1.900000E-002 Max:
2.413129E+002 Total: 1.618541E+003 Setup: 1.161743E+002
Edit: phCloneFieldList          Count: 70291   Min: 4.400000E-003 Max:
4.083400E+000 Total: 3.565259E+002 Setup: 1.113712E+002
Edit: phAssignValueToField      Count: 70291   Min: 9.700000E-003 Max:
1.777100E+000 Total: 5.765196E+002 Setup: 1.108866E+002

SetProviderType and SetFeeSchedule are both IronPython scripts, the other
three are C# edits that I'm passing my ExpandoObject directly to.

4.667 E+005 = almost 8 minutes...
1.108 E+002 = .1 seconds

Thanks in advance for any advice you can help me with.


class IronPythonScriptHost : PrimeEditBase {
ScriptSource mScriptSource;
ScriptEngine mEngine;
ScriptScope mScope;

public IronPythonScriptHost(string scriptText, string ScriptName,
CommandLine mCommandLine, string[] mEditParms, ScriptEngine engine)
: base(mCommandLine, mEditParms) {
mEditName     = ScriptName;
mIsScript     = true;
mEngine       = engine;
mScriptSource = mEngine.CreateScriptSourceFromString(scriptText,
mScope = mEngine.CreateScope();
public override void SetupEdit(dynamic editScope) {
mScope.SetVariable("PH", editScope);

public override void performEdit() {
try {
} catch (Exception ex) {
ExceptionOperations ExcOps = mEngine.GetService<ExceptionOperations>();
throw new Exception("Exception during execution of " + base.EditName + ". "
+ ex.Message + "\r\n" + ExcOps.FormatException(ex));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100812/c125f58b/attachment.html>

More information about the Ironpython-users mailing list