Skip to content

Instantly share code, notes, and snippets.

@alexkiro
Created March 11, 2016 16:55
Show Gist options
  • Save alexkiro/6ef0fd23ac0f080043ce to your computer and use it in GitHub Desktop.
Save alexkiro/6ef0fd23ac0f080043ce to your computer and use it in GitHub Desktop.
Measure BTree memory usage
from __future__ import print_function
import sys
import random
import psutil
from BTrees import IIBTree
from BTrees import IBBTree
mem_info = psutil.Process().memory_info()
human = "%s MiB (%s)" % (mem_info.rss / (1024*1024), mem_info)
print(human)
size = 10**8
if sys.argv[1] == "IB":
print("Using IB, adding %s values" % size)
data = IBBTree.IBBTree()
else:
print("Using II, adding %s values" % size)
data = IIBTree.IIBTree()
for i in range(size):
value = random.randint(-127, 127)
data[i] = value
mem_info = psutil.Process().memory_info()
human = "%s MiB (%s)" % (mem_info.rss / (1024*1024), mem_info)
print(human)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment