Back to index

python3.2  3.2.2
reperf.py
Go to the documentation of this file.
00001 import re
00002 import time
00003 
00004 def main():
00005     s = "\13hello\14 \13world\14 " * 1000
00006     p = re.compile(r"([\13\14])")
00007     timefunc(10, p.sub, "", s)
00008     timefunc(10, p.split, s)
00009     timefunc(10, p.findall, s)
00010 
00011 def timefunc(n, func, *args, **kw):
00012     t0 = time.clock()
00013     try:
00014         for i in range(n):
00015             result = func(*args, **kw)
00016         return result
00017     finally:
00018         t1 = time.clock()
00019         if n > 1:
00020             print(n, "times", end=' ')
00021         print(func.__name__, "%.3f" % (t1-t0), "CPU seconds")
00022 
00023 main()