[pypy-svn] r72306 - pypy/trunk/pypy/rpython/module/test

arigo at codespeak.net arigo at codespeak.net
Wed Mar 17 13:30:29 CET 2010


Author: arigo
Date: Wed Mar 17 13:30:28 2010
New Revision: 72306

Modified:
   pypy/trunk/pypy/rpython/module/test/test_ll_time.py
Log:
Replace sleep() with a version that happily consumes CPU time,
to make sure that time.clock() increase.


Modified: pypy/trunk/pypy/rpython/module/test/test_ll_time.py
==============================================================================
--- pypy/trunk/pypy/rpython/module/test/test_ll_time.py	(original)
+++ pypy/trunk/pypy/rpython/module/test/test_ll_time.py	Wed Mar 17 13:30:28 2010
@@ -16,25 +16,30 @@
         assert t0 <= res0 <= t1 <= res1
 
     def test_time_clock(self):
+        def sleep(t):
+            # a version of time.sleep() that consumes actual CPU time
+            start = time.clock()
+            while abs(time.clock() - start) <= t:
+                pass
         def f():
             return time.clock()
         t0 = time.clock()
-        time.sleep(0.011)
+        sleep(0.011)
         t1 = self.interpret(f, [])
-        time.sleep(0.011)
+        sleep(0.011)
         t2 = time.clock()
-        time.sleep(0.011)
+        sleep(0.011)
         t3 = self.interpret(f, [])
-        time.sleep(0.011)
+        sleep(0.011)
         t4 = time.clock()
-        time.sleep(0.011)
+        sleep(0.011)
         t5 = self.interpret(f, [])
-        time.sleep(0.011)
+        sleep(0.011)
         t6 = time.clock()
         # time.clock() and t1() might have a different notion of zero, so
         # we can only subtract two numbers returned by the same function.
         # Moreover they might have different precisions, but it should
-        # be at least 0.01 seconds, hence the sleeps.
+        # be at least 0.01 seconds, hence the "sleeps".
         assert 0.0199 <= t2-t0 <= 9.0
         assert 0.0199 <= t3-t1 <= t4-t0 <= 9.0
         assert 0.0199 <= t4-t2 <= t5-t1 <= t6-t0 <= 9.0



More information about the Pypy-commit mailing list