Created
August 23, 2022 14:11
-
-
Save rnag/bbc4143fe25580d7bcd91e554203c94d to your computer and use it in GitHub Desktop.
measuring dump JSON to terminal times
This file contains 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
from timeit import timeit | |
data = [ | |
{ | |
"eventStatus": "Failure", | |
"eventType": "Archive", | |
"objectName": "W12 BO Template", | |
"time": "2022-08-23T10:09:33.092Z" | |
}, | |
{ | |
"eventStatus": "Failure", | |
"eventType": "Archive", | |
"objectName": "W12 BO Template", | |
"time": "2022-08-23T09:06:33.786Z" | |
}, | |
{ | |
"eventStatus": "Failure", | |
"eventType": "Archive", | |
"objectName": "W12 BO Template", | |
"time": "2022-08-23T08:03:35.118Z" | |
}, | |
{ | |
"eventStatus": "Failure", | |
"eventType": "Archive", | |
"objectName": "W12 BO Template", | |
"time": "2022-08-23T07:00:32.683Z" | |
} | |
] | |
n = 1_000 | |
import json | |
import sys | |
print('timing json.dump: ', timeit('json.dump(data, sys.stdout)', number=n, globals=globals())) | |
print('timing print: ', timeit('print(json.dumps(data))', number=n, globals=globals())) | |
# - RESULTS - | |
# | |
# timing json.dump: 0.044549165999999994 | |
# timing print: 0.005745374999999997 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment