[pypy-commit] pypy pyparser-improvements: add a target for benchmarking just the parser

cfbolz pypy.commits at gmail.com
Mon Mar 12 12:52:44 EDT 2018


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: pyparser-improvements
Changeset: r93976:73fdbc94d5d4
Date: 2018-03-12 16:59 +0100
http://bitbucket.org/pypy/pypy/changeset/73fdbc94d5d4/

Log:	add a target for benchmarking just the parser

diff --git a/pypy/interpreter/pyparser/pyparse.py b/pypy/interpreter/pyparser/pyparse.py
--- a/pypy/interpreter/pyparser/pyparse.py
+++ b/pypy/interpreter/pyparser/pyparse.py
@@ -132,7 +132,11 @@
                         w_message = space.str(e.get_w_value(space))
                         raise error.SyntaxError(space.text_w(w_message))
                     raise
+        if enc is not None:
+            compile_info.encoding = enc
+        return self._parse(textsrc, compile_info)
 
+    def _parse(self, textsrc, compile_info):
         flags = compile_info.flags
 
         # The tokenizer is very picky about how it wants its input.
@@ -188,6 +192,4 @@
         finally:
             # Avoid hanging onto the tree.
             self.root = None
-        if enc is not None:
-            compile_info.encoding = enc
         return tree
diff --git a/pypy/interpreter/pyparser/targetparse.py b/pypy/interpreter/pyparser/targetparse.py
new file mode 100644
--- /dev/null
+++ b/pypy/interpreter/pyparser/targetparse.py
@@ -0,0 +1,39 @@
+import sys
+import os
+ROOT =  os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
+print ROOT
+sys.path.insert(0, str(ROOT))
+import time
+from pypy.interpreter.pyparser import pyparse
+
+
+
+with file("../../../rpython/rlib/unicodedata/unicodedb_5_2_0.py") as f:
+    s = f.read()
+
+class FakeSpace(object):
+    pass
+
+fakespace = FakeSpace()
+
+def bench(title):
+    a = time.clock()
+    info = pyparse.CompileInfo("<string>", "exec")
+    parser = pyparse.PythonParser(fakespace)
+    tree = parser._parse(s, info)
+    b = time.clock()
+    print title, (b-a)
+
+
+def entry_point(argv):
+    bench("foo")
+
+    return 0
+
+# _____ Define and setup target ___
+
+def target(*args):
+    return entry_point, None
+
+if __name__ == '__main__':
+    entry_point(sys.argv)


More information about the pypy-commit mailing list