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. 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.
Below is the code that I'm executing, followed by the output I received with the timings. Notice that when the rate is "X" or a numeric value, the script execution is much faster than when I enter the exception handler. I'm running the following version of IronPython: IronPython 2.6.1 (2.6.10920.0) on .NET 4.0.30319.1 [CODE] from System.Diagnostics import Stopwatch t = Stopwatch() s = Stopwatch() e = Stopwatch() t.Start() s.Start() Rate = PH.GetFieldString("RATE") s.Stop() rateGet = s.Elapsed.TotalMilliseconds s.Reset(); if Rate == "X": s.Start() #Sets some values... s.Stop() rateSet = s.Elapsed.TotalMilliseconds else: try: e.Start() fRate = float(Rate) e.Stop() if fRate > 15: s.Start() #Sets some values... s.Stop(); rateSet = s.Elapsed.TotalMilliseconds else: s.Start() #Sets some values... s.Stop(); rateSet = s.Elapsed.TotalMilliseconds except ValueError: e.Stop() s.Start() #Sets some values... s.Stop(); rateSet = s.Elapsed.TotalMilliseconds t.Stop() print "Total: " + str(t.Elapsed.TotalMilliseconds) + " RateGet: " + str(rateGet) + " RateSets: " + str(rateSet) + " Exception Handle: " + str(e.Elapsed.TotalMilliseconds) + " Rate: " + str(Rate) s.Reset() t.Reset() [Output] Total: 55.402 RateGet: 0.4303 RateSets: 7.5158 Exception Handle: 37.335 Rate: B Total: 10.026 RateGet: 0.1507 RateSets: 0.38 Exception Handle: 0.1118 Rate: 30 Total: 1.1308 RateGet: 0.1442 RateSets: 0.3553 Exception Handle: 0.0838 Rate: 25 Total: 19.9077 RateGet: 0.145 RateSets: 0.3954 Exception Handle: 18.8591 Rate: A Total: 18.8859 RateGet: 0.147 RateSets: 1.427 Exception Handle: 16.8182 Rate: A Total: 18.2704 RateGet: 0.2301 RateSets: 0.6179 Exception Handle: 16.6897 Rate: A Total: 17.5447 RateGet: 0.1401 RateSets: 0.3707 Exception Handle: 16.5629 Rate: A Total: 17.43 RateGet: 0.147 RateSets: 0.3796 Exception Handle: 16.4166 Rate: B Total: 17.3939 RateGet: 0.1377 RateSets: 0.3602 Exception Handle: 16.4227 Rate: B Total: 17.3923 RateGet: 0.1418 RateSets: 0.3788 Exception Handle: 16.3627 Rate: B Total: 1.1993 RateGet: 0.1134 RateSets: 0.6827 Exception Handle: 0.0 Rate: X Total: 18.6249 RateGet: 0.1057 RateSets: 0.3808 Exception Handle: 17.6504 Rate: A Total: 17.0674 RateGet: 0.0745 RateSets: 0.3229 Exception Handle: 16.3526 Rate: L Total: 17.4021 RateGet: 0.0867 RateSets: 0.3521 Exception Handle: 16.6277 Rate: B Total: 17.4973 RateGet: 0.0741 RateSets: 0.4258 Exception Handle: 16.5078 Rate: A Total: 17.4251 RateGet: 0.0842 RateSets: 0.3391 Exception Handle: 16.652 Rate: A Total: 17.3559 RateGet: 0.0757 RateSets: 0.3253 Exception Handle: 16.6212 Rate: A Total: 17.885 RateGet: 0.0765 RateSets: 0.3277 Exception Handle: 17.1354 Rate: A Total: 17.898 RateGet: 0.0769 RateSets: 0.4226 Exception Handle: 16.8992 Rate: A Total: 17.9381 RateGet: 0.0773 RateSets: 0.3257 Exception Handle: 17.2023 Rate: A Total: 17.6204 RateGet: 0.0786 RateSets: 0.3444 Exception Handle: 16.851 Rate: B Total: 22.097 RateGet: 0.2589 RateSets: 0.4376 Exception Handle: 20.3052 Rate: B Total: 16.817 RateGet: 0.0782 RateSets: 0.3249 Exception Handle: 16.0783 Rate: A Total: 18.1557 RateGet: 0.0798 RateSets: 0.3715 Exception Handle: 17.3765 Rate: A Total: 17.3117 RateGet: 0.0765 RateSets: 0.4347 Exception Handle: 16.3117 Rate: A Total: 17.3433 RateGet: 0.0854 RateSets: 0.3415 Exception Handle: 16.5674 Rate: A Total: 17.8072 RateGet: 0.0741 RateSets: 0.3602 Exception Handle: 17.0503 Rate: A Total: 21.0285 RateGet: 1.312 RateSets: 1.9955 Exception Handle: 17.2302 Rate: A Total: 17.4693 RateGet: 0.0733 RateSets: 0.269 Exception Handle: 16.7947 Rate: A Total: 17.1699 RateGet: 0.0806 RateSets: 0.2666 Exception Handle: 16.4798 Rate: A Total: 17.2841 RateGet: 0.083 RateSets: 0.2649 Exception Handle: 16.6168 Rate: A Total: 17.5892 RateGet: 0.0773 RateSets: 0.3731 Exception Handle: 16.7914 Rate: L Total: 16.9316 RateGet: 0.0761 RateSets: 0.3233 Exception Handle: 16.0309 Rate: L Total: 17.3713 RateGet: 0.0725 RateSets: 0.254 Exception Handle: 16.7209 Rate: L Total: 17.1828 RateGet: 0.0794 RateSets: 0.2686 Exception Handle: 16.505 Rate: L Total: 17.302 RateGet: 0.0786 RateSets: 0.2556 Exception Handle: 16.6391 Rate: A Total: 17.319 RateGet: 0.0757 RateSets: 0.3314 Exception Handle: 16.413 Rate: A Total: 17.0678 RateGet: 0.0794 RateSets: 0.269 Exception Handle: 16.3802 Rate: A Total: 0.8533 RateGet: 0.0749 RateSets: 0.3889 Exception Handle: 0.0522 Rate: 30 Total: 17.6281 RateGet: 0.0725 RateSets: 0.3298 Exception Handle: 16.8968 Rate: A Total: 17.6294 RateGet: 0.0769 RateSets: 0.2556 Exception Handle: 16.9576 Rate: A Total: 18.3972 RateGet: 0.0725 RateSets: 0.2698 Exception Handle: 17.708 Rate: L Total: 17.7363 RateGet: 0.0822 RateSets: 0.3196 Exception Handle: 16.8319 Rate: L Total: 17.8036 RateGet: 0.0798 RateSets: 0.2807 Exception Handle: 17.1071 Rate: L Total: 17.3473 RateGet: 0.0761 RateSets: 0.2544 Exception Handle: 16.6857 Rate: L
_______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com