Skip to content

Instantly share code, notes, and snippets.

@colesbury
Last active November 13, 2023 01:21
Show Gist options
  • Save colesbury/dd888920a1eacb97794fb6be2446dc10 to your computer and use it in GitHub Desktop.
Save colesbury/dd888920a1eacb97794fb6be2446dc10 to your computer and use it in GitHub Desktop.
import time
import json
import math
import subprocess
LOOPS = 1000
def main():
times = []
for i in range(1):
start = time.time()
for n in range(LOOPS):
tmp = json.loads('{"res": "ok"}')
#tmp = json.load(open("/Users/sgross/Downloads/large-file.json", "r"))
end = time.time()
times.append((end - start) / LOOPS * 1e9)
print((end - start) / LOOPS * 1e9)
main()
import time
import json
import math
import subprocess
import sys
if len(sys.argv) > 1:
N = int(sys.argv[1])
else:
N = 500
def main():
times = []
for _ in range(N):
v = subprocess.run(["./python.exe", "test_json.py"], capture_output=True)
res = v.stdout.decode('utf-8').strip()
times.append(float(res))
minimum = min(times)
maximum = max(times)
avg = sum(times)/N
var = sum((x - avg)**2 for x in times) / N
stddev = math.sqrt(var)
print(f"{minimum=}")
print(f"{maximum=}")
print(f"{avg=} +/- {stddev=}")
main()
@colesbury
Copy link
Author

./python.exe test_json_repeat.py 500

BEFORE:

minimum=761.0321044921875
maximum=960.1116180419922
avg=781.9304466247559 +/- stddev=22.09558416016643

AFTER:

minimum=771.7609405517578
maximum=972.9862213134767
avg=788.0878448486328 +/- stddev=19.02220149366413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment