Created
July 28, 2025 06:07
-
-
Save aivarsk/f8aea7864155c948e8fb2e3b72f8dd61 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 json | |
| import timeit | |
| def nested_list(depth): | |
| l = [True] | |
| for _ in range(depth - 1): | |
| l = [l] | |
| return l | |
| def repeated_dict(elems, depth): | |
| d = {} | |
| for key in range(elems): | |
| d[key] = nested_list(depth) | |
| return d | |
| for n in range(1, 2): | |
| for depth in range(1, 10): | |
| input = repeated_dict(n, depth) | |
| t = timeit.timeit("json.dumps(input)", number=1000000, globals=globals()) | |
| print(n, depth, t, sep=",") | |
| for depth in range(10, 100, 10): | |
| input = repeated_dict(n, depth) | |
| t = timeit.timeit("json.dumps(input)", number=100000, globals=globals()) | |
| print(n, depth, t, sep=",") | |
| for depth in range(100, 1000, 100): | |
| input = repeated_dict(n, depth) | |
| t = timeit.timeit("json.dumps(input)", number=10000, globals=globals()) | |
| print(n, depth, t, sep=",") | |
| for depth in range(1000, 5000, 1000): | |
| input = repeated_dict(n, depth) | |
| t = timeit.timeit("json.dumps(input)", number=1000, globals=globals()) | |
| print(n, depth, t, sep=",") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment