Skip to content

Commit a318714

Browse files
authored
Merge pull request #199 from seddonym/add-benchmark-for-mostly-cached
Benchmark using the cache for a few misses
2 parents a311e6c + b4504ce commit a318714

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

tests/benchmarking/test_benchmarking.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
import json
3+
import importlib
34
from pathlib import Path
45
from grimp.adaptors.graph import ImportGraph
56
from grimp import PackageDependency, Route
@@ -299,14 +300,39 @@ def test_build_django_uncached(benchmark):
299300
_run_benchmark(benchmark, grimp.build_graph, "django", cache_dir=None)
300301

301302

302-
def test_build_django_from_cache(benchmark):
303+
def test_build_django_from_cache_no_misses(benchmark):
303304
"""
304305
Benchmarks building a graph of real package - in this case Django.
305306
306-
This benchmark uses the cache.
307+
This benchmark fully utilizes the cache.
307308
"""
308309
# Populate the cache first, before beginning the benchmark.
309310
grimp.build_graph("django")
311+
312+
_run_benchmark(benchmark, grimp.build_graph, "django")
313+
314+
315+
@pytest.mark.parametrize(
316+
"number_of_misses",
317+
(
318+
2, # Fewer than the likely number of CPUs.
319+
15, # A bit more than the likely number of CPUs.
320+
),
321+
)
322+
def test_build_django_from_cache_a_few_misses(benchmark, number_of_misses):
323+
"""
324+
Benchmarks building a graph of real package - in this case Django.
325+
326+
This benchmark utilizes the cache except for a few modules, which we add.
327+
"""
328+
# Populate the cache first, before beginning the benchmark.
329+
grimp.build_graph("django")
330+
# Add a module which won't be in the cache.
331+
django_path = Path(importlib.util.find_spec("django").origin).parent
332+
for i in range(number_of_misses):
333+
new_module = django_path / f"new_module_{i}.py"
334+
new_module.write_text("from django.db import models")
335+
310336
_run_benchmark(benchmark, grimp.build_graph, "django")
311337

312338

0 commit comments

Comments
 (0)