Skip to content

Instantly share code, notes, and snippets.

@pitrou
Last active August 29, 2015 14:03
Show Gist options
  • Save pitrou/0d2c082fad365d401b7b to your computer and use it in GitHub Desktop.
Save pitrou/0d2c082fad365d401b7b to your computer and use it in GitHub Desktop.
import gc
import sys
import llvm.core as lc
import llvm.ee as le
# Cache plausible return values for sys.getallocatedblocks() - _base, to avoid
# allocating them later.
_int_pool = {}
for i in range(-2048, 2048):
_int_pool[i] = i
del i
NITERS = 100
alloc = [0] * NITERS
gc.collect()
_base = sys.getallocatedblocks()
for i in range(NITERS):
mod = lc.Module.new("foobar")
if 1:
eb = le.EngineBuilder.new(mod)
eb.opt(3)
eb = mod = None
gc.collect()
alloc[i] = _int_pool[sys.getallocatedblocks() - _base]
print("alloc =", alloc)
print("deltas =", [b - a for (a, b) in zip(alloc, alloc[1:])])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment