Skip to content

Instantly share code, notes, and snippets.

@aivarsk
Created July 30, 2025 21:56
Show Gist options
  • Select an option

  • Save aivarsk/302b1d3d1e093d5de4b5def7a0e23f59 to your computer and use it in GitHub Desktop.

Select an option

Save aivarsk/302b1d3d1e093d5de4b5def7a0e23f59 to your computer and use it in GitHub Desktop.
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
check_circular = True
for depth in (1, 2, 4):
for n in range(1, 10):
input = repeated_dict(n, depth)
t = timeit.timeit(
"json.dumps(input, check_circular=check_circular)",
number=1000000,
globals=globals(),
)
print(n, depth, t, sep=",")
for n in range(10, 100, 10):
input = repeated_dict(n, depth)
t = timeit.timeit(
"json.dumps(input, check_circular=check_circular)",
number=100000,
globals=globals(),
)
print(n, depth, t, sep=",")
for n in range(100, 1000, 100):
input = repeated_dict(n, depth)
t = timeit.timeit(
"json.dumps(input, check_circular=check_circular)",
number=10000,
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