import asjsonp import json import time import sys def test_asjsonp(text: str, count: int): start = time.perf_counter_ns() for _ in range(count): asjsonp.loads(text) end = time.perf_counter_ns() print(f"asjsonp.loads: {(end - start) / (1000 ** 2)}ms") def test_json(text: str, count: int): start = time.perf_counter_ns() for _ in range(count): json.loads(text) end = time.perf_counter_ns() print(f"json.loads: {(end - start) / (1000 ** 2)}ms") input_file = "./benchmark/data/api.opensource.org.json" count = 1000 for i, arg in enumerate(sys.argv[1:]): if arg == "-i": input_file = sys.argv[i + 2] elif arg == "-c": count = int(sys.argv[i + 2]) text = open(input_file, "r").read() print(f"Benchmarking file {input_file} with {count} iterations") test_asjsonp(text, count) test_json(text, count)