Skip to content

Commit

Permalink
Added package version to CPU time benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
eerimoq committed Jul 30, 2018
1 parent 0e7a19d commit 27ab18b
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 35 deletions.
22 changes: 11 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,17 @@ to make them fit the user application.
$ env PYTHONPATH=. python3 examples/benchmarks/json/cpu.py
Parsed 'examples/benchmarks/json/data.json' 1 time(s) in:
PACKAGE SECONDS RATIO
textparser 0.10 100%
lark (LALR) 0.26 265%
funcparserlib 0.34 358%
parsimonious 0.41 423%
textx 0.53 548%
pyparsing 0.69 715%
pyleri 0.81 836%
parsy 0.94 976%
lark (Earley) 1.88 1949%
parsita 2.31 2401%
PACKAGE SECONDS RATIO VERSION
textparser 0.10 100% 0.14.0
lark (LALR) 0.26 265% 0.6.2
funcparserlib 0.34 358% unknown
parsimonious 0.41 423% unknown
textx 0.53 548% 1.7.1
pyparsing 0.69 715% 2.2.0
pyleri 0.81 836% 1.2.2
parsy 0.94 976% 1.2.0
lark (Earley) 1.88 1949% 0.6.2
parsita 2.31 2401% unknown
$
Contributing
Expand Down
51 changes: 27 additions & 24 deletions examples/benchmarks/json/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
$ env PYTHONPATH=. python3 examples/benchmarks/json/cpu.py
Parsed 'examples/benchmarks/json/data.json' 1 time(s) in:
PACKAGE SECONDS RATIO
textparser 0.10 100%
lark (LALR) 0.26 265%
funcparserlib 0.34 358%
parsimonious 0.41 423%
textx 0.53 548%
pyparsing 0.69 715%
pyleri 0.81 836%
parsy 0.94 976%
lark (Earley) 1.88 1949%
parsita 2.31 2401%
PACKAGE SECONDS RATIO VERSION
textparser 0.10 100% 0.14.0
lark (LALR) 0.26 265% 0.6.2
funcparserlib 0.34 358% unknown
parsimonious 0.41 423% unknown
textx 0.53 548% 1.7.1
pyparsing 0.69 715% 2.2.0
pyleri 0.81 836% 1.2.2
parsy 0.94 976% 1.2.0
lark (Earley) 1.88 1949% 0.6.2
parsita 2.31 2401% unknown
$
"""
Expand Down Expand Up @@ -85,30 +85,33 @@ def parse_time(_json_string, _iterations):

# Parse comparison output.
measurements = [
('textparser', textparser_time),
('lark (LALR)', lark_lalr_time),
('lark (Earley)', lark_earley_time),
('pyparsing', pyparsing_time),
('parsita', parsita_time),
('funcparserlib', funcparserlib_time),
('parsy', parsy_time),
('parsimonious', parsimonious_time),
('pyleri', pyleri_time),
('textx', textx_time)
('textparser', textparser_time, textparser_json.version()),
('lark (LALR)', lark_lalr_time, lark_json.version()),
('lark (Earley)', lark_earley_time, lark_json.version()),
('pyparsing', pyparsing_time, pyparsing_json.version()),
('parsita', parsita_time, parsita_json.version()),
('funcparserlib', funcparserlib_time, funcparserlib_json.version()),
('parsy', parsy_time, parsy_json.version()),
('parsimonious', parsimonious_time, parsimonious_json.version()),
('pyleri', pyleri_time, pyleri_json.version()),
('textx', textx_time, textx_json.version())
]

measurements = sorted(measurements, key=lambda m: m[1])

print()
print("Parsed '{}' {} time(s) in:".format(DATA_JSON, ITERATIONS))
print()
print('PACKAGE SECONDS RATIO')
print('PACKAGE SECONDS RATIO VERSION')

for package, seconds in measurements:
for package, seconds, version in measurements:
try:
ratio = int(round(100 * (seconds / textparser_time), 0))
ratio = '{:5}'.format(ratio)
except OverflowError:
ratio = ' inf'

print('{:14s} {:7.02f} {}%'.format(package, seconds, ratio))
print('{:14s} {:7.02f} {}% {}'.format(package,
seconds,
ratio,
version))
4 changes: 4 additions & 0 deletions examples/benchmarks/json/parsers/funcparserlib_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,7 @@ def parse(json_string):
tokenizer = create_tokenizer()

return grammar.parse(tokenize(tokenizer, json_string))


def version():
return 'unknown'
5 changes: 5 additions & 0 deletions examples/benchmarks/json/parsers/lark_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import timeit

import lark
from lark import Lark


Expand Down Expand Up @@ -71,3 +72,7 @@ def parse_earley(json_string):
parser='earley')

return parser.parse(json_string)


def version():
return lark.__version__
4 changes: 4 additions & 0 deletions examples/benchmarks/json/parsers/parsimonious_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ def _parse():

def parse(json_string):
return grammar.parse(json_string)


def version():
return 'unknown'
4 changes: 4 additions & 0 deletions examples/benchmarks/json/parsers/parsita_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ def _parse():

def parse(json_string):
return JsonParsers.value.parse(json_string)


def version():
return 'unknown'
5 changes: 5 additions & 0 deletions examples/benchmarks/json/parsers/parsy_json.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import timeit

import parsy
from parsy import generate
from parsy import regex
from parsy import string
Expand Down Expand Up @@ -68,3 +69,7 @@ def _parse():

def parse(json_string):
return json.parse(json_string)


def version():
return parsy.__version__
5 changes: 5 additions & 0 deletions examples/benchmarks/json/parsers/pyleri_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import timeit

import pyleri
from pyleri import Ref
from pyleri import Choice
from pyleri import Grammar
Expand Down Expand Up @@ -57,3 +58,7 @@ def _parse():

def parse(json_string):
return JsonGrammar().parse(json_string)


def version():
return pyleri.__version__
5 changes: 5 additions & 0 deletions examples/benchmarks/json/parsers/pyparsing_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import timeit

import pyparsing
from pyparsing import Keyword
from pyparsing import Suppress
from pyparsing import dblQuotedString
Expand Down Expand Up @@ -56,3 +57,7 @@ def parse(json_string):
grammar = create_grammar()

return grammar.parseString(json_string).asList()


def version():
return pyparsing.__version__
4 changes: 4 additions & 0 deletions examples/benchmarks/json/parsers/textparser_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ def _parse():

def parse(json_string):
return Parser().parse(json_string)


def version():
return textparser.__version__
5 changes: 5 additions & 0 deletions examples/benchmarks/json/parsers/textx_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import timeit

import textx
from textx import metamodel_from_str


Expand Down Expand Up @@ -48,3 +49,7 @@ def parse(json_string):
parser = metamodel_from_str(GRAMMAR)

return parser.model_from_str(json_string)


def version():
return textx.__version__

0 comments on commit 27ab18b

Please sign in to comment.