[IronPython] Speed test

Dino Viehland dinov at exchange.microsoft.com
Wed Apr 19 17:00:34 CEST 2006


Interop w/ C# shouldn't really cost you that much - it should actually be able to give you speed gains as you fall back into the static world...

Do you know if most of the time is being spent in the XmlTextReader or in IronPython after that?  And I'm having trouble parsing "but things slow down significantly when I try to enumerate the StringCollection into a PythonEngine".  Is this just doing a set variable, or are you looping over the collection and doing a set variable one at a time?

Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of JoeSox
Sent: Tuesday, April 18, 2006 11:34 PM
To: Discussion of IronPython
Subject: Re: [IronPython] Speed test

Thanks Dino for double-checking me there.

I'm not sure if you, or anyone else, is interested as to why I asked
but I'll surely entertain you and some others for a couple of seconds.
:)

I also get the same results from the unpp test, my last test results were...
1st run: 0.1718750
2 to about 6th run: 0.0
est. 7th run: 0.0156250

Don't get me wrong, I am not complaining.  However, I am trying to
rewrite ConceptNet 2.1 to be used with .Net (just as a learning
experience mostly for myself, some odd reason I find it fun, wheither
I ever get enough time to complete it, is another matter) and
ConceptNet loads, by default, three huge text files of those predicate
sequence lines which is then loaded into a very large semantic
network.

At first I tried loading these predicate lines into a
StringCollection, which works great when using
System.IO.File.ReadAllLines()
but things slow down significantly when I try to enumerate the
StringCollection into a PythonEngine.  So, it looks like staying away
from .Net objects, as much as possible, and actually rewriting the
Python code to blend with IronPython is currently looks like the way I
need to go.

So I was able to speed test the loading of the three predicate files
and ConceptNet's creation of some huge dictionary objects which is
used for its semantic mapping.
Both apps basically load:
(1.4mb) predicates_concise_nonkline.txt: loads 27000 predicates
(10.2mb) predicates_concise_kline.txt: loads 174000 predicates
(19.5mb) predicates_nonconcise_nonkline.txt: loads 348000 predicates

Python clocks in at 52.907753 seconds*

My C# Method clocks in at 4:40.4845

I created a new XmlTextReader to read in the settings file which holds
the 3 predicate file paths. I then set time1
then call:
     ipEngine1.SetVariable("pred_file", predfile);
     ipEngine1.Execute(@"db.load_predicates_file(pred_file)");

After the XmlTextReader is closed I set time2:
time2 = DateTime.Now;
MessageBox.Show(Convert.ToString(time2.Subtract(time1)));

* I added the time lines around the method:
        time1=time.clock()
        self.load_predicates()
        time2=time.clock()
to class ConceptNetDB


So I will keep on tweaking things until I get a better load time for
the predicate files.  I am thinking out loud here but I may need to
pass the loading to the Console and then grab the semantic mapping
dictionaries that way.

Just in case anyone is really bored I uploaded my import file that is
currently my version of ConceptNet's ConceptNetDB.py.

http://www.joeswammi.com/projects/CNUDB.py

in the C# speed test above I call
            //IronPython...
            ipEngine1.Execute("import sys");
            ipEngine1.Execute("sys.path.append('E:\')");
            ipEngine1.Execute("import CNUDB");
            ipEngine1.Execute("db=CNUDB.ConceptNetDB()");
            string predfile = "";
            DateTime time1 = new DateTime();
            DateTime time2 = new DateTime();

before reading the XML settings file.

--
Joseph

On 4/17/06, Dino Viehland <dinov at exchange.microsoft.com> wrote:
> IronPython is slower to get things going the first time (because we end up compiling to IL and then JITing the code); it's after that when we really start to shine.
>
> The first time you run this we will take longer to execute it, but if you do it a second time we'll report zero.  When I run it the first time I get ~.20 seconds, the second time I get 0 seconds - which is just below the precision of the clock.
>
>
> Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of JoeSox
> Sent: Sunday, April 16, 2006 8:07 AM
> To: Discussion of IronPython
> Subject: [IronPython] Speed test
>
> Am I doing this speed test correctly using the script and process below?
>
> I have unpp.py on a usb jumpdrive E
> -------
> #unpp.py
> import time
>
> def unpp(pp):
>    time1=time.clock()
>    toks = pp.strip(' ()\n').split()
>    pred = toks[0]
>    args = ' '.join(toks[1:])[1:-1].split('" "')
>    f,i = map(lambda x:int(x.split('=')[1]),args.pop().split(';')[:2])
>    time2=time.clock()
>    print pred,args[0],args[1],f,i
>    print time1
>    print time2
>    print "-- unpp took",str(round(time2-time1,6)),'seconds. --\n'
> ----------
>
> ===== I run a test in IDLE
> Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on win32
> IDLE 1.1.2      ==== No Subprocess ====
> >>> import sys
> >>> sys.path.append('E/')
> >>> import unpp
> >>> p=unpp
> >>> p.unpp('(CapableOf \"red bicycle\" \"pump\" \"f=2;i=1;\")')
> CapableOf red bicycle pump 2 1
> 50.3331431788
> 50.3331713947
> -- unpp took 2.8e-005 seconds. --
> ===== END of IDLE test 2.8e-005 = 0.000028
>
>
> ====== I run same test in IronPythonConsole
> IronPython 1.0.2280 (Beta) on .NET 2.0.50727.42
> Copyright (c) Microsoft Corporation. All rights reserved.
> >>> import sys
> >>> sys.path.append('E:/')
> >>> import unpp
> >>> p=unpp
> >>> p.unpp('(CapableOf \"red bicycle\" \"pump\" \"f=2;i=1;\")')
> CapableOf red bicycle pump 2 1
> 63280770878.0
> 63280770878.0
> -- unpp took 0.046867 seconds. --
> ===== END of IronPythonConsole test
>
> If I am doing this correctly, there seems to be a big process time
> difference, does this seem to be correct, or I am missing something or
> doing the time() incorrectly?
> Thanks!
> --
> Joseph
_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list