Created
September 28, 2021 21:34
-
-
Save Dascienz/f44e8b7729960c2c0a293c2a85f56089 to your computer and use it in GitHub Desktop.
Test JSON Size
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 json | |
import os | |
import sys | |
import uuid | |
import datetime | |
config = {} | |
size = 1000 | |
for i in range(size): | |
config[i] = {"key": "value} | |
output = json.dumps(config) | |
print("Estimated size: " + str(sys.getsizeof(output) / 1024) + "KB") | |
with open("test.json", 'wb') as outfile: | |
outfile.write(output.encode()) | |
print("Actual size: " + str(os.path.getsize('test.json') / 1024) + "KB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment