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

Class TestPerformanceBenchmarks

python/tests/test_performance_benchmarks.py:21–340  ·  view source on GitHub ↗

Performance benchmark tests with threshold validation.

Source from the content-addressed store, hash-verified

19
20@pytest.mark.slow
21class TestPerformanceBenchmarks:
22 """Performance benchmark tests with threshold validation."""
23
24 def test_insertion_performance_small(self):
25 """Test insertion performance for small datasets."""
26 size = 1000
27 tree = BPlusTreeMap(capacity=32)
28
29 start_time = time.perf_counter()
30 for i in range(size):
31 tree[i] = f"value_{i}"
32 elapsed = time.perf_counter() - start_time
33
34 # Should complete in reasonable time (< 0.1 seconds)
35 assert elapsed < 0.1, f"Small insertion took {elapsed:.3f}s, expected < 0.1s"
36
37 # Verify all items inserted correctly
38 assert len(tree) == size
39 assert tree[0] == "value_0"
40 assert tree[size - 1] == f"value_{size - 1}"
41
42 def test_insertion_performance_medium(self):
43 """Test insertion performance for medium datasets."""
44 size = 10000
45 tree = BPlusTreeMap(capacity=32)
46
47 start_time = time.perf_counter()
48 for i in range(size):
49 tree[i] = f"value_{i}"
50 elapsed = time.perf_counter() - start_time
51
52 # Should complete in reasonable time (< 1 second)
53 assert elapsed < 1.0, f"Medium insertion took {elapsed:.3f}s, expected < 1.0s"
54
55 # Verify correctness
56 assert len(tree) == size
57
58 # Check performance metrics
59 ops_per_second = size / elapsed
60 assert ops_per_second > 5000, f"Insertion rate {ops_per_second:.0f} ops/s, expected > 5000"
61
62 def test_bulk_loading_performance(self):
63 """Test bulk loading performance advantage."""
64 size = 10000
65 data = [(i, f"value_{i}") for i in range(size)]
66
67 # Test bulk loading
68 start_time = time.perf_counter()
69 tree_bulk = BPlusTreeMap.from_sorted_items(data, capacity=32)
70 bulk_time = time.perf_counter() - start_time
71
72 # Test individual insertion
73 start_time = time.perf_counter()
74 tree_individual = BPlusTreeMap(capacity=32)
75 for k, v in data:
76 tree_individual[k] = v
77 individual_time = time.perf_counter() - start_time
78

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected