Demonstrate the impact of capacity tuning.
()
| 289 | |
| 290 | |
| 291 | def 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 | |
| 323 | def main(): |
no test coverage detected