From 04cd5d0850ad3af7e64a45d063f3fef72c4b8dca Mon Sep 17 00:00:00 2001 From: Erez Shinan Date: Mon, 20 Mar 2017 19:06:13 +0200 Subject: [PATCH] Updated benchmarks due to error in memory measurement (Thanks Jamie!) --- docs/json_tutorial.md | 15 ++++++++------- examples/json_parser.py | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/json_tutorial.md b/docs/json_tutorial.md index c83d6c7..9f3fbf1 100644 --- a/docs/json_tutorial.md +++ b/docs/json_tutorial.md @@ -327,7 +327,7 @@ class TreeToJson(Transformer): true = lambda self, _: True false = lambda self, _: False -json_parser = Lark(json_grammar, start='value') +json_parser = Lark(json_grammar, start='value', lexer='standard') if __name__ == '__main__': with open(sys.argv[1]) as f: @@ -419,12 +419,13 @@ I measured memory consumption using a little script called [memusg](https://gist | Code | CPython Time | PyPy Time | CPython Mem | PyPy Mem |:-----|:-------------|:------------|:----------|:--------- -| Lark - Earley | 36s | 4.3s | 6.2M | 1.2M | -| Lark - LALR(1) | 7s | 1.3s | 0.6M | 0.3M | -| Lark - LALR(1) tree-less | 4.2s | 1.1s | 0.4M | 0.3M | -| PyParsing ([Parser](http://pyparsing.wikispaces.com/file/view/jsonParser.py)) | 32s | 4.1s | 0.4M | 0.2M | -| funcparserlib ([Parser](https://github.com/vlasovskikh/funcparserlib/blob/master/funcparserlib/tests/json.py)) | 11s | 1.9s | 0.5M | 0.3M | -| Parsimonious ([Parser](https://gist.githubusercontent.com/reclosedev/5222560/raw/5e97cf7eb62c3a3671885ec170577285e891f7d5/parsimonious_json.py)) | ? | 7s | ? | 1.4M | +| Lark - Earley *(with lexer)* | 42s | 4s | 1167M | 608M | +| Lark - LALR(1) | 8s | 1.53s | 453M | 266M | +| Lark - LALR(1) tree-less | 4.76s | 1.23s | 70M | 134M | +| PyParsing ([Parser](http://pyparsing.wikispaces.com/file/view/jsonParser.py)) | 32s | 3.53s | 443M | 225M | +| funcparserlib ([Parser](https://github.com/vlasovskikh/funcparserlib/blob/master/funcparserlib/tests/json.py)) | 8.5s | 1.3s | 483M | 293M | +| Parsimonious ([Parser](https://gist.githubusercontent.com/reclosedev/5222560/raw/5e97cf7eb62c3a3671885ec170577285e891f7d5/parsimonious_json.py)) | ? | 5.7s | ? | 1545M | + I added a few other parsers for comparison. PyParsing and funcparselib fair pretty well in their memory usage (they don't build a tree), but they can't compete with the run-time speed of LALR(1). diff --git a/examples/json_parser.py b/examples/json_parser.py index a67ae4b..4f5feaf 100644 --- a/examples/json_parser.py +++ b/examples/json_parser.py @@ -47,7 +47,7 @@ class TreeToJson(Transformer): true = lambda self, _: True false = lambda self, _: False -# json_parser = Lark(json_grammar, parser='earley') +# json_parser = Lark(json_grammar, parser='earley', lexer='standard') # def parse(x): # return TreeToJson().transform(json_parser.parse(x)) @@ -72,7 +72,7 @@ def test(): assert j == json.loads(test_json) if __name__ == '__main__': - test() + # test() with open(sys.argv[1]) as f: print(parse(f.read()))