Skip to content

Commit

Permalink
Updated benchmarks due to error in memory measurement (Thanks Jamie!)
Browse files Browse the repository at this point in the history
  • Loading branch information
erezsh committed Mar 20, 2017
1 parent 00811a7 commit 04cd5d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions docs/json_tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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).

Expand Down
4 changes: 2 additions & 2 deletions examples/json_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def string(self, s):
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))

Expand All @@ -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()))

0 comments on commit 04cd5d0

Please sign in to comment.