SRE vs PRE: speed
Oleg Broytmann
phd at phd.fep.ru
Thu Jul 5 09:22:28 EDT 2001
Hello!
My company doen't want to switch from python 1.5.2 to 2.0+ - our CTO is
very disappointed with SRE speed. SRE is 3-4 times lsower. Any plans to
make it faster?
The following program
---------- test_re.py ----------
import pre, sre, profile, types
I_NUM = 1000 # number of iterations
pre_comp_sub_pat = pre.compile('/')
sre_comp_sub_pat = sre.compile('/')
def Iterate(func):
assert type(func) == types.FunctionType
for i in range(0, I_NUM):
func()
def pre_sub():
pre.sub('/','.','/burja/mgloju/nebo/kroet')
def sre_sub():
sre.sub('/','.','/burja/mgloju/nebo/kroet')
def pre_comp_sub():
pre_comp_sub_pat.sub('.','/burja/mgloju/nebo/kroet')
def sre_comp_sub():
sre_comp_sub_pat.sub('.','/burja/mgloju/nebo/kroet')
if __name__ == '__main__':
profile.run('Iterate(pre_sub)')
profile.run('Iterate(sre_sub)')
profile.run('Iterate(pre_comp_sub)')
profile.run('Iterate(sre_comp_sub)')
---------- /test_re.py ----------
produces the following results:
---------- test_re.log ----------
6005 function calls in 0.773 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.758 0.758 <string>:1(?)
1000 0.023 0.000 0.031 0.000 pre.py:114(_cachecompile)
1000 0.109 0.000 0.641 0.001 pre.py:153(sub)
1 0.000 0.000 0.008 0.008 pre.py:234(compile)
1 0.008 0.008 0.008 0.008 pre.py:264(__init__)
1000 0.078 0.000 0.500 0.001 pre.py:331(sub)
1000 0.375 0.000 0.422 0.000 pre.py:344(subn)
1 0.016 0.016 0.773 0.773 profile:0(Iterate(pre_sub))
0 0.000 0.000 profile:0(profiler)
1000 0.047 0.000 0.047 0.000 string.py:119(join)
1000 0.078 0.000 0.719 0.001 test_re.py:14(pre_sub)
1 0.039 0.039 0.758 0.758 test_re.py:9(Iterate)
26003 function calls in 3.031 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 3.023 3.023 <string>:1(?)
1 0.008 0.008 3.031 3.031 profile:0(Iterate(sre_sub))
0 0.000 0.000 profile:0(profiler)
1000 0.094 0.000 2.656 0.003 sre.py:113(_sub)
1000 0.609 0.001 2.563 0.003 sre.py:117(_subn)
4000 0.445 0.000 1.164 0.000 sre.py:123(filter)
1000 0.164 0.000 2.867 0.003 sre.py:49(sub)
1000 0.055 0.000 0.125 0.000 sre.py:87(_join)
1000 0.047 0.000 0.047 0.000 sre.py:91(_compile)
1000 0.055 0.000 0.133 0.000 sre_parse.py:161(__init__)
3000 0.180 0.000 0.180 0.000 sre_parse.py:165(__next)
2000 0.219 0.000 0.320 0.000 sre_parse.py:184(get)
1000 0.211 0.000 0.664 0.001 sre_parse.py:603(parse_template)
4000 0.516 0.000 0.719 0.000 sre_parse.py:664(expand_template)
5000 0.273 0.000 0.273 0.000 string.py:119(join)
1000 0.094 0.000 2.961 0.003 test_re.py:17(sre_sub)
1 0.063 0.063 3.023 3.023 test_re.py:9(Iterate)
4003 function calls in 0.742 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.742 0.742 <string>:1(?)
1000 0.109 0.000 0.594 0.001 pre.py:331(sub)
1000 0.438 0.000 0.484 0.000 pre.py:344(subn)
1 0.000 0.000 0.742 0.742 profile:0(Iterate(pre_comp_sub))
0 0.000 0.000 profile:0(profiler)
1000 0.047 0.000 0.047 0.000 string.py:119(join)
1000 0.117 0.000 0.711 0.001 test_re.py:20(pre_comp_sub)
1 0.031 0.031 0.742 0.742 test_re.py:9(Iterate)
24003 function calls in 2.672 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 2.672 2.672 <string>:1(?)
1 0.000 0.000 2.672 2.672 profile:0(Iterate(sre_comp_sub))
0 0.000 0.000 profile:0(profiler)
1000 0.086 0.000 2.492 0.002 sre.py:113(_sub)
1000 0.586 0.001 2.406 0.002 sre.py:117(_subn)
4000 0.289 0.000 0.984 0.000 sre.py:123(filter)
1000 0.094 0.000 0.172 0.000 sre.py:87(_join)
1000 0.094 0.000 0.172 0.000 sre_parse.py:161(__init__)
3000 0.141 0.000 0.141 0.000 sre_parse.py:165(__next)
2000 0.203 0.000 0.266 0.000 sre_parse.py:184(get)
1000 0.227 0.000 0.664 0.001 sre_parse.py:603(parse_template)
4000 0.484 0.000 0.695 0.000 sre_parse.py:664(expand_template)
5000 0.289 0.000 0.289 0.000 string.py:119(join)
1000 0.125 0.000 2.617 0.003 test_re.py:23(sre_comp_sub)
1 0.055 0.055 2.672 2.672 test_re.py:9(Iterate)
---------- /test_re.log ----------
Oleg.
----
Oleg Broytmann http://phd.pp.ru/ phd at phd.pp.ru
Programmers don't die, they just GOSUB without RETURN.
More information about the Python-list
mailing list