PageRenderTime 55ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/lib-python/2/test/reperf.py

https://bitbucket.org/kcr/pypy
Python | 23 lines | 22 code | 1 blank | 0 comment | 0 complexity | 9212926a1cb0513dbdd6bd1ba5dd6596 MD5 | raw file
Possible License(s): Apache-2.0
  1. import re
  2. import time
  3. def main():
  4. s = "\13hello\14 \13world\14 " * 1000
  5. p = re.compile(r"([\13\14])")
  6. timefunc(10, p.sub, "", s)
  7. timefunc(10, p.split, s)
  8. timefunc(10, p.findall, s)
  9. def timefunc(n, func, *args, **kw):
  10. t0 = time.clock()
  11. try:
  12. for i in range(n):
  13. result = func(*args, **kw)
  14. return result
  15. finally:
  16. t1 = time.clock()
  17. if n > 1:
  18. print n, "times",
  19. print func.__name__, "%.3f" % (t1-t0), "CPU seconds"
  20. main()