11import argparse
2+ import os
23import timeit
34from pathlib import Path
45
56import json
67
8+ FAST = bool (os .getenv ('FAST' ))
9+ THIS_DIR = Path (__file__ ).parent
10+
711cases = [
8- ("medium_response" , Path ( "../jiter/benches/medium_response.json" ).read_bytes ()),
12+ ("medium_response" , ( THIS_DIR / "../jiter/benches/medium_response.json" ).read_bytes ()),
913 (
1014 "massive_ints_array" ,
11- Path ( "../jiter/benches/massive_ints_array.json" ).read_bytes (),
15+ ( THIS_DIR / "../jiter/benches/massive_ints_array.json" ).read_bytes (),
1216 ),
1317 ("array_short_strings" , "[{}]" .format (", " .join ('"123"' for _ in range (100_000 )))),
1418 (
@@ -31,10 +35,13 @@ def run_bench(func, d):
3135 timer = timeit .Timer (
3236 "func(json_data)" , setup = "" , globals = {"func" : func , "json_data" : d }
3337 )
34- n , t = timer .autorange ()
35- iter_time = t / n
36- # print(f'{func.__module__}.{func.__name__}', iter_time)
37- return iter_time
38+ if FAST :
39+ return timer .timeit (1 )
40+ else :
41+ n , t = timer .autorange ()
42+ iter_time = t / n
43+ # print(f'{func.__module__}.{func.__name__}', iter_time)
44+ return iter_time
3845
3946
4047def setup_orjson ():
@@ -46,13 +53,13 @@ def setup_orjson():
4653def setup_jiter_cache ():
4754 import jiter
4855
49- return lambda data : jiter .from_json (data , cache_strings = True )
56+ return lambda data : jiter .from_json (data , cache_mode = True )
5057
5158
5259def setup_jiter ():
5360 import jiter
5461
55- return lambda data : jiter .from_json (data , cache_strings = False )
62+ return lambda data : jiter .from_json (data , cache_mode = False )
5663
5764
5865def setup_ujson ():
0 commit comments