[IronPython] Exception Performance

Michael Foord fuzzyman at voidspace.org.uk
Tue Aug 3 17:45:10 CEST 2010


On 03/08/2010 16:41, Jeff Hardy wrote:
> Hi Cory,
>
> On Mon, Aug 2, 2010 at 12:41 PM, Cory Brostowicz
> <cory.brostowicz at gmail.com>  wrote:
>    
>> Hello,
>> I noticed the performance in one of my python scripts has really bad
>> performance, so I started profiling different sections of the script to find
>> out  where the issue is.  It turns out, the exception handle seems to add
>> the biggest chunk of time.
>>      
> IronPython 2.6 and earlier rely on the .NET exception mechanism.
> .NET's exception handling is extremely slow, whereas CPython has an
> extremely fast exception handling system. I don't know the details of
> why each is the way it is, though - engineering tradeoffs, I guess.
>
> IronPython 2.7 will have a 'lightweight' exception mechanism that
> should be closer to the performance of CPython.
>
>    
>> I've fairly new to the Python language, so if
>> there is a better way to do what I'm doing, then please let me know.
>>      
> Unfortunately, I think that's pretty much idiomatic Python, which
> often relies on it's very fast exception handling. In .NET you use the
> Try* methods instead, which don't throw exceptions.
>
> If you don't need CPython compatibility, you could use
> System.Double.TryParse
> (http://msdn.microsoft.com/en-us/library/994c0zb1.aspx), but I don't
> know how to use out parameters from IronPython off the top of my head.
>
>    

out parameters are returned as extra values when you make the call. (So 
you don't pass in the "out" parameter - but you get an extra return value.)

Michael

> On an unrelated note, you can write your print statement as:
>
>      print "Total: %s RateGet: %s RateSets: %s Exception Handle: %s
> Rate: %s" % (t.Elapsed.TotalMilliseconds, rateGet, rateSet,
> e.Elapsed.TotalMilliseconds, Rate)
>
> - Jeff
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>    


-- 
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog

READ CAREFULLY. By accepting and reading this email you agree, on behalf of your employer, to release me from all obligations and waivers arising from any and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your employer, its partners, licensors, agents and assigns, in perpetuity, without prejudice to my ongoing rights and privileges. You further represent that you have the authority to release me from any BOGUS AGREEMENTS on behalf of your employer.





More information about the Ironpython-users mailing list