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

Function benchmark_iteration

python/examples/performance_demo.py:123–172  ·  view source on GitHub ↗

Benchmark full iteration performance.

()

Source from the content-addressed store, hash-verified

121
122
123def benchmark_iteration():
124 """Benchmark full iteration performance."""
125 print("=== Full Iteration Performance ===\n")
126
127 sizes = [1000, 5000, 10000, 20000]
128
129 for size in sizes:
130 print(f"Dataset size: {size:,} items")
131
132 data = create_test_data(size)
133
134 # Setup data structures
135 bplustree = BPlusTreeMap(capacity=64)
136 bplustree.update(data)
137
138 regular_dict = dict(data)
139
140 if HAS_SORTEDDICT:
141 sorted_dict = SortedDict(data)
142
143 # B+ Tree iteration
144 def bplus_iterate():
145 return sum(1 for _ in bplustree.items())
146
147 bplus_time, _ = benchmark_function(bplus_iterate)
148 print(f" B+ Tree: {bplus_time*1000:.3f} ms")
149
150 # Dict iteration (unsorted)
151 def dict_iterate():
152 return sum(1 for _ in regular_dict.items())
153
154 dict_time, _ = benchmark_function(dict_iterate)
155 print(f" Dict: {dict_time*1000:.3f} ms")
156
157 # Sorted dict iteration
158 def sorted_dict_iterate():
159 return sum(1 for _ in sorted(regular_dict.items()))
160
161 sorted_time, _ = benchmark_function(sorted_dict_iterate)
162 print(f" Dict sorted: {sorted_time*1000:.3f} ms")
163
164 if HAS_SORTEDDICT:
165
166 def sorteddict_iterate():
167 return sum(1 for _ in sorted_dict.items())
168
169 sd_time, _ = benchmark_function(sorteddict_iterate)
170 print(f" SortedDict: {sd_time*1000:.3f} ms")
171
172 print()
173
174
175def benchmark_insertion():

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