Skip to content

Instantly share code, notes, and snippets.

@bjourne
Created March 22, 2026 23:36
Show Gist options
  • Select an option

  • Save bjourne/c67b11bda92929e469eb1dd607945095 to your computer and use it in GitHub Desktop.

Select an option

Save bjourne/c67b11bda92929e469eb1dd607945095 to your computer and use it in GitHub Desktop.
overallocation stuff
from random import shuffle
from time import time
def make_lists(L):
L1, L2, L3 = [], [], []
for e in L:
L1.append(e)
L2.append(e)
L3.append(e)
return L1, L2, L3
def make_many(L, n):
for _ in range(n):
ret = make_lists(L)
return ret
N_APPENDS = 100_000_000
def trial(n_els):
n_loops = N_APPENDS // n_els
L = list(range(n_els))
shuffle(L)
start = time()
make_many(L, n_loops)
delta = time() - start
per_app = (delta / N_APPENDS) * 1e9
print("%12.1f %12d %12.0f" % (delta, n_els, per_app))
print("%-12s %-12s %-12s" % ("tot (s)", "n_els", "append (ns)"))
sizes = sum([[e*10**i for e in [2, 5, 10]] for i in range(5)], [])
for n_els in sizes:
trial(n_els)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment