from timeit import timeit

setup = """
from io import BytesIO
import json
from ijson.backends.python import basic_parse
from validater import parse, validate
schema = parse([{"userid": "int"}])
data_normal = json.dumps([{"userid": "123"}], ensure_ascii=False)
data_deep = '[' * 8000 + ']' * 8000
obj_normal = BytesIO(data_normal.encode('utf-8'))
obj_deep = BytesIO(data_deep.encode('utf-8'))
"""

print('ijson'.center(60, '-'))
s = """
obj_normal.seek(0)
for event, value in basic_parse(obj_normal):
    pass
"""
print("normal data: %.6f sec" % timeit(s, setup, number=1000))

s = """
obj_deep.seek(0)
try:
    for event, value in basic_parse(obj_deep):
        pass
except RecursionError:
    pass
"""
print("deep data: %.6f sec" % timeit(s, setup, number=1000))


print('validater'.center(60, '-'))
s = """
obj_normal.seek(0)
err, val = validate(obj_normal, schema)
"""
print("normal data: %.6f sec" % timeit(s, setup, number=1000))
s = """
obj_deep.seek(0)
err, val = validate(obj_deep, schema)
"""
print("deep data: %.6f sec" % timeit(s, setup, number=1000))


print('standard json'.center(60, '-'))
s = """
obj_normal.seek(0)
json.loads(data_normal)
"""
print("normal data: %.6f sec" % timeit(s, setup, number=1000))
s = """
obj_deep.seek(0)
try:
    json.loads(data_deep)
except RecursionError:
    pass
"""
print("deep data: %.6f sec" % timeit(s, setup, number=1000))

@@ -113,16 +113,82 @@
 c_parse%0A
+from ijson.backends.yajl2_cffi import basic_parse as cbasic_parse%0A
 from val
@@ -217,16 +217,16 @@
 alidate%0A
-
 schema =
@@ -464,24 +464,31 @@
 print('ijson
+ python
 '.center(60,
@@ -669,24 +669,24 @@
 eek(0)%0Atry:%0A
-
     for even
@@ -828,24 +828,406 @@
 er=1000))%0A%0A%0A
+print('ijson yajl2_cffi'.center(60, '-'))%0As = %22%22%22%0Aobj_normal.seek(0)%0Afor event, value in cbasic_parse(obj_normal):%0A    pass%0A%22%22%22%0Aprint(%22normal data: %25.6f sec%22 %25 timeit(s, setup, number=1000))%0A%0As = %22%22%22%0Aobj_deep.seek(0)%0Atry:%0A    for event, value in cbasic_parse(obj_deep):%0A        pass%0Aexcept RecursionError:%0A    pass%0A%22%22%22%0Aprint(%22deep data: %25.6f sec%22 %25 timeit(s, setup, number=1000))%0A%0A%0A
 print('valid

update benchmark