[pypy-svn] r38067 - pypy/branch/jit-virtual-world/pypy/jit/goal/demo
arigo at codespeak.net
arigo at codespeak.net
Wed Feb 7 16:08:53 CET 2007
Author: arigo
Date: Wed Feb 7 16:08:50 2007
New Revision: 38067
Added:
pypy/branch/jit-virtual-world/pypy/jit/goal/demo/ (props changed)
pypy/branch/jit-virtual-world/pypy/jit/goal/demo/f1.py (contents, props changed)
pypy/branch/jit-virtual-world/pypy/jit/goal/demo/factorial.py (contents, props changed)
pypy/branch/jit-virtual-world/pypy/jit/goal/demo/factorialrec.py (contents, props changed)
Log:
Demo scripts whose machine code can be looked at (run with PYPYJITLOG=filename).
Added: pypy/branch/jit-virtual-world/pypy/jit/goal/demo/f1.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-virtual-world/pypy/jit/goal/demo/f1.py Wed Feb 7 16:08:50 2007
@@ -0,0 +1,30 @@
+import time
+
+
+ZERO = 0
+
+def f1(n):
+ "Arbitrary test function."
+ i = 0
+ x = 1
+ while i<n:
+ j = ZERO
+ while j<=i:
+ j = j + 1
+ x = x + (i&j)
+ i = i + 1
+ return x
+
+
+import pypyjit
+pypyjit.enable(f1.func_code)
+
+res = f1(2117)
+print res
+N = 5
+start = time.time()
+for i in range(N):
+ assert f1(2117) == res
+end = time.time()
+
+print '%d iterations, time per iteration: %s' % (N, (end-start)/N)
Added: pypy/branch/jit-virtual-world/pypy/jit/goal/demo/factorial.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-virtual-world/pypy/jit/goal/demo/factorial.py Wed Feb 7 16:08:50 2007
@@ -0,0 +1,14 @@
+import time
+
+
+def f(n):
+ r = 1
+ while n > 1:
+ r *= n
+ n -= 1
+ return r
+
+import pypyjit
+pypyjit.enable(f.func_code)
+
+print f(7)
Added: pypy/branch/jit-virtual-world/pypy/jit/goal/demo/factorialrec.py
==============================================================================
--- (empty file)
+++ pypy/branch/jit-virtual-world/pypy/jit/goal/demo/factorialrec.py Wed Feb 7 16:08:50 2007
@@ -0,0 +1,13 @@
+import time
+
+
+def f(n):
+ if n > 1:
+ return n * f(n-1)
+ else:
+ return 1
+
+import pypyjit
+pypyjit.enable(f.func_code)
+
+print f(7)
More information about the pypy-svn
mailing list