Last active
November 13, 2023 01:21
-
-
Save colesbury/dd888920a1eacb97794fb6be2446dc10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BEFORE:
AFTER: