[Python-Dev] 2.5 slower than 2.4 for some things? (original) (raw)
ocean ocean at m2.ccsnet.ne.jp
Wed Jun 13 19:17:25 CEST 2007
- Previous message: [Python-Dev] 2.5 slower than 2.4 for some things?
- Next message: [Python-Dev] 2.5 slower than 2.4 for some things?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Meanwhile I tried to replace the parsing I did with Plex by re.Scanner. And again there is a remarkable speed difference. Again python2.5 is slower:
try: from re import Scanner except: from sre import Scanner pars = {} order = [] count = 0 def par(scanner,name): global count, order, pars if name in ['caller','e','pi']: return name if name not in pars.keys(): pars[name] = ('ns', count) order.append(name) ret = 'a[%d]'%count count += 1 else: ret = 'a[%d]'%(order.index(name)) return ret scanner = Scanner([ (r"x", lambda y,x: x), (r"[a-zA-Z]+.", lambda y,x: x), (r"[a-z]+(", lambda y,x: x), (r"[a-zA-Z]\w*", par), (r"\d+.\d*", lambda y,x: x), (r"\d+", lambda y,x: x), (r"+|-|*|/", lambda y,x: x), (r"\s+", None), (r")+", lambda y,x: x), (r"(+", lambda y,x: x), (r",", lambda y,x: x), ]) import profile import pstats def run(): arg = '+amp*exp(-(x-pos)/fwhm)' for i in range(100): scanner.scan(arg) profile.run('run()','profscanner') p = pstats.Stats('profscanner') p.stripdirs() p.sortstats('cumulative') p.printstats()
Well, I tried this script, there was no big difference. Python2.4 0.772sec Python2.5 0.816sec
Probably I found one reason comparation for classic style class is slower on Python2.5. Comparation function instance_compare() calls PyErr_GivenExceptionMatches(), and it was just flag operation on 2.4. But on 2.5, probably related to introduction of BaseException, it checks inherited type tuple. (ie: PyExceptionInstance_Check)
- Previous message: [Python-Dev] 2.5 slower than 2.4 for some things?
- Next message: [Python-Dev] 2.5 slower than 2.4 for some things?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]