From 350b6034d247c8e3008f643ec1f6feffbb30f19d Mon Sep 17 00:00:00 2001 From: David Seddon Date: Tue, 14 Jan 2025 10:47:30 +0000 Subject: [PATCH] Improve cache handling in benchmark tests Prior to this, the benchmark would use the file cache if it was already there, giving misleading results. --- tests/benchmarking/test_benchmarking.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/benchmarking/test_benchmarking.py b/tests/benchmarking/test_benchmarking.py index 784c3f14..1988375a 100644 --- a/tests/benchmarking/test_benchmarking.py +++ b/tests/benchmarking/test_benchmarking.py @@ -34,10 +34,30 @@ def large_graph(): ) -def test_build_django(benchmark): +def test_build_django_uncached(benchmark): """ Benchmarks building a graph of real package - in this case Django. + + In this benchmark, the cache is turned off. + """ + fn = lambda: grimp.build_graph("django", cache_dir=None) + if hasattr(benchmark, "pendantic"): + # Running with pytest-benchmark + benchmark.pedantic(fn, rounds=3) + else: + # Running with codspeed. + benchmark(fn) + + +def test_build_django_from_cache(benchmark): """ + Benchmarks building a graph of real package - in this case Django. + + This benchmark uses the cache. + """ + # Populate the cache first, before beginning the benchmark. + grimp.build_graph("django") + fn = lambda: grimp.build_graph("django") if hasattr(benchmark, "pendantic"): # Running with pytest-benchmark