[pypy-svn] pypy jit-lsprofile: (fijal, alex): Write extregistry for read_timestamp.
alex_gaynor
commits-noreply at bitbucket.org
Sun Mar 13 19:37:09 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: jit-lsprofile
Changeset: r42564:01c036925078
Date: 2011-03-13 14:36 -0400
http://bitbucket.org/pypy/pypy/changeset/01c036925078/
Log: (fijal, alex): Write extregistry for read_timestamp.
diff --git a/pypy/rlib/rtimer.py b/pypy/rlib/rtimer.py
--- a/pypy/rlib/rtimer.py
+++ b/pypy/rlib/rtimer.py
@@ -3,6 +3,7 @@
import py
from pypy.rlib.rarithmetic import r_longlong
+from pypy.rpython.extregistry import ExtRegistryEntry
from pypy.rpython.lltypesystem import rffi
from pypy.tool.autopath import pypydir
@@ -18,4 +19,16 @@
)
def read_timestamp():
- return c_read_timestamp()
\ No newline at end of file
+ return c_read_timestamp()
+
+
+class ReadTimestampEntry(ExtRegistryEntry):
+ _about_ = read_timestamp
+
+ def compute_annotation(self):
+ from pypy.annotation.model import SomeInteger
+ return SomeInteger(knowntype=r_longlong)
+
+ def specialize_call(self, hop):
+ hop.exception_cannot_occur()
+ return hop.genop("ll_read_timestamp")
\ No newline at end of file
diff --git a/pypy/rlib/test/test_rtimer.py b/pypy/rlib/test/test_rtimer.py
--- a/pypy/rlib/test/test_rtimer.py
+++ b/pypy/rlib/test/test_rtimer.py
@@ -1,14 +1,23 @@
import time
from pypy.rlib.rtimer import read_timestamp
+from pypy.rpython.test.test_llinterp import interpret
-def test_timer():
+def timer():
t1 = read_timestamp()
start = time.time()
- while time.time() - start < 1.0:
+ while time.time() - start < 0.1:
# busy wait
pass
t2 = read_timestamp()
+ return t2 - t1
+
+def test_timer():
+ diff = timer()
# We're counting ticks, verify they look correct
- assert t2 - t1 > 1000
+ assert diff > 1000
+
+def test_annotation():
+ diff = interpret(timer, [])
+ assert diff > 1000
\ No newline at end of file
More information about the Pypy-commit
mailing list