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

Function benchmark_insertion

python/examples/performance_demo.py:175–218  ·  view source on GitHub ↗

Benchmark insertion performance.

()

Source from the content-addressed store, hash-verified

173
174
175def benchmark_insertion():
176 """Benchmark insertion performance."""
177 print("=== Insertion Performance ===\n")
178
179 sizes = [1000, 5000, 10000]
180
181 for size in sizes:
182 print(f"Inserting {size:,} items")
183
184 data = create_test_data(size)
185 random.shuffle(data) # Random insertion order
186
187 # B+ Tree insertion
188 def bplus_insert():
189 tree = BPlusTreeMap(capacity=64)
190 for key, value in data:
191 tree[key] = value
192 return tree
193
194 bplus_time, _ = benchmark_function(bplus_insert)
195 print(f" B+ Tree: {bplus_time*1000:.3f} ms")
196
197 # Dict insertion
198 def dict_insert():
199 d = {}
200 for key, value in data:
201 d[key] = value
202 return d
203
204 dict_time, _ = benchmark_function(dict_insert)
205 print(f" Dict: {dict_time*1000:.3f} ms")
206
207 if HAS_SORTEDDICT:
208
209 def sorted_dict_insert():
210 sd = SortedDict()
211 for key, value in data:
212 sd[key] = value
213 return sd
214
215 sd_time, _ = benchmark_function(sorted_dict_insert)
216 print(f" SortedDict: {sd_time*1000:.3f} ms")
217
218 print()
219
220
221def benchmark_memory_usage():

Callers 1

mainFunction · 0.85

Calls 2

create_test_dataFunction · 0.85
benchmark_functionFunction · 0.85

Tested by

no test coverage detected