PyXR

c:\python24\lib \ test \ reperf.py



0001 import re
0002 import time
0003 
0004 def main():
0005     s = "\13hello\14 \13world\14 " * 1000
0006     p = re.compile(r"([\13\14])")
0007     timefunc(10, p.sub, "", s)
0008     timefunc(10, p.split, s)
0009     timefunc(10, p.findall, s)
0010 
0011 def timefunc(n, func, *args, **kw):
0012     t0 = time.clock()
0013     try:
0014         for i in range(n):
0015             result = func(*args, **kw)
0016         return result
0017     finally:
0018         t1 = time.clock()
0019         if n > 1:
0020             print n, "times",
0021         print func.__name__, "%.3f" % (t1-t0), "CPU seconds"
0022 
0023 main()
0024 

Generated by PyXR 0.9.4
SourceForge.net Logo