[IronPython] Performance issue when calling a function with **kw

Asaf Kleinbort asaf at itstructures.com
Sun Aug 3 12:31:03 CEST 2008


Hi all,

I am new to this list, so I'll first introduce myself.

I am working at IT Structures (www.itstructures.com)  in Israel. Our service
Is written in C#, but most of the backend implementation is written in
IronPython.

While doing performance analysis of our application, I came across the
following interesting bug (?):

 

Calling a function with **kw takes about 10 times more time than calling a
function with a simple dictionary.  The difference exists also in cpython
but there the differences is hardly noticed.

 

Here is a code snippet to clarify:

.

def func_kw(kw):

    return sum(kw.itervalues())

 

def func(**kw):

    return sum(kw.itervalues())

    

def measure(n):

    dct = {'1':2,'2':2,'3':2,'4':2,'5':2,'6':2}

    start = time.clock()

    for i in xrange(n):

        func_kw(dct)

    duration_without = time.clock()-start

    start = time.clock()

    for i in xrange(n):

        func(**dct)

    duration_with = time.clock()-start

    return (duration_without,duration_with)

.

 

Running measure(10**6) 10 times in a loop and calculating the mean we get
the following results (in seconds):

 

In IronPython:

WITH **KW: mean=5.56493157650, stddev=0.0649572929575.

WITHOUT: mean=0.86113346808, stddev=0.0142532589459.

 

In Python:

 WITH **KW: mean=1.70669562131, stddev=0.0230977726849.

 WITHOUT: mean=0.782945815118, stddev=0.00572116553432. 

 

(IronPython version: IronPython 1.1.1 (1.1.1) on .NET 2.0.50727.1433

Python version: Python 2.5.1)

 

Does anyone know if this is going to improve in version 2.0?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080803/1daa481e/attachment.html>


More information about the Ironpython-users mailing list