PageRenderTime 241ms CodeModel.GetById 237ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/pypy/rlib/test/test_rtimer.py

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