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

Function capacity_tuning_demo

python/examples/performance_demo.py:291–320  ·  view source on GitHub ↗

Demonstrate the impact of capacity tuning.

()

Source from the content-addressed store, hash-verified

289
290
291def capacity_tuning_demo():
292 """Demonstrate the impact of capacity tuning."""
293 print("=== Capacity Tuning Impact ===\n")
294
295 size = 5000
296 data = create_test_data(size)
297 capacities = [4, 8, 16, 32, 64, 128]
298
299 print(f"Range query performance with {size:,} items (different capacities):")
300
301 results = []
302 for capacity in capacities:
303 tree = BPlusTreeMap(capacity=capacity)
304 tree.update(data)
305
306 # Benchmark a range query
307 def range_query():
308 return list(tree.range(1000, 1100))
309
310 query_time, _ = benchmark_function(range_query)
311 results.append((capacity, query_time))
312 print(f" Capacity {capacity:3d}: {query_time*1000:.3f} ms")
313
314 # Find optimal capacity
315 best_capacity, best_time = min(results, key=lambda x: x[1])
316 worst_capacity, worst_time = max(results, key=lambda x: x[1])
317
318 print(f"\n Best: Capacity {best_capacity} ({best_time*1000:.3f} ms)")
319 print(f" Worst: Capacity {worst_capacity} ({worst_time*1000:.3f} ms)")
320 print(f" Improvement: {worst_time/best_time:.1f}x faster with optimal capacity")
321
322
323def main():

Callers 1

mainFunction · 0.85

Calls 4

updateMethod · 0.95
BPlusTreeMapClass · 0.90
create_test_dataFunction · 0.85
benchmark_functionFunction · 0.85

Tested by

no test coverage detected