MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / benchmark_memory_usage

Function benchmark_memory_usage

python/examples/performance_demo.py:221–243  ·  view source on GitHub ↗

Demonstrate memory efficiency.

()

Source from the content-addressed store, hash-verified

219
220
221def benchmark_memory_usage():
222 """Demonstrate memory efficiency."""
223 print("=== Memory Usage Estimation ===\n")
224
225 import sys
226
227 size = 10000
228 data = create_test_data(size)
229
230 # B+ Tree
231 bplustree = BPlusTreeMap(capacity=64)
232 bplustree.update(data)
233
234 # Dict
235 regular_dict = dict(data)
236
237 print(f"For {size:,} items:")
238 print(
239 f" B+ Tree: ~{sys.getsizeof(bplustree) + sum(sys.getsizeof(x) for x in [bplustree.keys(), bplustree.values()]):,} bytes"
240 )
241 print(f" Dict: ~{sys.getsizeof(regular_dict):,} bytes")
242 print("\nNote: Memory usage depends on Python implementation and object overhead.")
243 print("B+ Tree may use more memory per item but provides better cache locality.")
244
245
246def demonstrate_early_termination():

Callers 1

mainFunction · 0.85

Calls 5

updateMethod · 0.95
keysMethod · 0.95
valuesMethod · 0.95
BPlusTreeMapClass · 0.90
create_test_dataFunction · 0.85

Tested by

no test coverage detected