repo: init
This commit is contained in:
33
benchmark/__main__.py
Normal file
33
benchmark/__main__.py
Normal file
@ -0,0 +1,33 @@
|
||||
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)
|
||||
1
benchmark/data/api.opensource.org.json
Normal file
1
benchmark/data/api.opensource.org.json
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user