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

Function test_prefetch_microbench

python/tests/test_prefetch_microbench.py:30–58  ·  view source on GitHub ↗

Run lookup benchmark to compare prefetch hint impact.

()

Source from the content-addressed store, hash-verified

28
29
30def test_prefetch_microbench():
31 """Run lookup benchmark to compare prefetch hint impact."""
32 # Prepare dataset
33 size = 100_000
34 keys = list(range(size))
35 random.shuffle(keys)
36 lookup_keys = random.sample(keys, min(10_000, size))
37
38 # Build tree
39 tree = BPlusTree(capacity=128)
40 for key in keys:
41 tree[key] = key * 2
42
43 def lookup():
44 for k in lookup_keys:
45 _ = tree[k]
46
47 # Warm up and measure
48 iterations = 5
49 gc.collect()
50 gc.disable()
51 start = time.perf_counter()
52 for _ in range(iterations):
53 lookup()
54 total = time.perf_counter() - start
55 gc.enable()
56
57 ns_per_op = total * 1e9 / (iterations * len(lookup_keys))
58 print(f"Lookup performance: {ns_per_op:.1f} ns/op")

Callers

nothing calls this directly

Calls 2

BPlusTreeClass · 0.90
lookupFunction · 0.85

Tested by

no test coverage detected