Skip to content

Commit 63da233

Browse files
authored
Merge pull request #184 from seddonym/more-benchmarks-feb2025
More benchmarks feb2025
2 parents 06401f4 + 7e1c324 commit 63da233

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

tests/benchmarking/test_benchmarking.py

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,41 @@ def test_copy_graph(large_graph, benchmark):
424424
_run_benchmark(benchmark, lambda: deepcopy(large_graph))
425425

426426

427-
def test_graph_contains_module(large_graph, benchmark):
428-
def f(n):
429-
for i in range(n):
430-
_ = f"foo{i}" in large_graph.modules
427+
def test_modules_property_first_access(large_graph, benchmark):
428+
def f():
429+
# Benchmarking runs multiple times over the same object, so we need
430+
# to bust the cache first. The easiest way to do this is to add a module.
431+
large_graph.add_module("cachebuster")
432+
433+
# Accessing the modules property is what we're benchmarking.
434+
_ = large_graph.modules
435+
436+
_run_benchmark(benchmark, f)
437+
438+
439+
def test_modules_property_many_accesses(large_graph, benchmark):
440+
def f():
441+
# Benchmarking runs multiple times over the same object, so we need
442+
# to bust the cache first. The easiest way to do this is to add a module.
443+
large_graph.add_module("cachebuster")
444+
445+
# Accessing the modules property is what we're benchmarking.
446+
for i in range(1000):
447+
_ = large_graph.modules
448+
449+
_run_benchmark(benchmark, f)
431450

432-
_run_benchmark(benchmark, f, 100)
433451

452+
def test_get_import_details(benchmark):
453+
graph = ImportGraph()
454+
iterations = 100
455+
for i in range(iterations, 1):
456+
graph.add_import(
457+
importer=f"blue_{i}", imported=f"green_{i}", line_contents="...", line_number=i
458+
)
434459

435-
def test_iterate_over_modules_in_graph(large_graph, benchmark):
436460
def f():
437-
for module in large_graph.modules:
438-
_ = module
461+
for i in range(iterations):
462+
graph.get_import_details(importer=f"blue_{i}", imported=f"green_{i}")
439463

440464
_run_benchmark(benchmark, f)

0 commit comments

Comments
 (0)