|
1 | 1 | import pytest |
2 | 2 | import json |
| 3 | +import importlib |
3 | 4 | from pathlib import Path |
4 | 5 | from grimp.adaptors.graph import ImportGraph |
5 | 6 | from grimp import PackageDependency, Route |
@@ -299,14 +300,39 @@ def test_build_django_uncached(benchmark): |
299 | 300 | _run_benchmark(benchmark, grimp.build_graph, "django", cache_dir=None) |
300 | 301 |
|
301 | 302 |
|
302 | | -def test_build_django_from_cache(benchmark): |
| 303 | +def test_build_django_from_cache_no_misses(benchmark): |
303 | 304 | """ |
304 | 305 | Benchmarks building a graph of real package - in this case Django. |
305 | 306 |
|
306 | | - This benchmark uses the cache. |
| 307 | + This benchmark fully utilizes the cache. |
307 | 308 | """ |
308 | 309 | # Populate the cache first, before beginning the benchmark. |
309 | 310 | 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 | + |
310 | 336 | _run_benchmark(benchmark, grimp.build_graph, "django") |
311 | 337 |
|
312 | 338 |
|
|
0 commit comments