PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/rpython/rlib/test/test_rtimer.py

https://bitbucket.org/kkris/pypy
Python | 28 lines | 21 code | 5 blank | 2 comment | 1 complexity | ce1fbab9779f8ff2c4aa538a8954bc39 MD5 | raw file
  1. import time
  2. from rpython.rlib.rtimer import read_timestamp
  3. from rpython.rtyper.test.test_llinterp import interpret
  4. from rpython.translator.c.test.test_genc import compile
  5. def timer():
  6. t1 = read_timestamp()
  7. start = time.time()
  8. while time.time() - start < 0.1:
  9. # busy wait
  10. pass
  11. t2 = read_timestamp()
  12. return t2 - t1
  13. def test_timer():
  14. diff = timer()
  15. # We're counting ticks, verify they look correct
  16. assert diff > 1000
  17. def test_annotation():
  18. diff = interpret(timer, [])
  19. assert diff > 1000
  20. def test_compile_c():
  21. function = compile(timer, [])
  22. diff = function()
  23. assert diff > 1000