Browse Source

Updated benchmarks due to error in memory measurement (Thanks Jamie!)

tags/gm/2021-09-23T00Z/github.com--lark-parser-lark/0.5.1
Erez Shinan 7 years ago
parent
commit
04cd5d0850
2 changed files with 10 additions and 9 deletions
  1. +8
    -7
      docs/json_tutorial.md
  2. +2
    -2
      examples/json_parser.py

+ 8
- 7
docs/json_tutorial.md View File

@@ -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).



+ 2
- 2
examples/json_parser.py View File

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


Loading…
Cancel
Save