Skip to content

Speed up benchmark cpu tests with _BORG_BENCHMARK_CPU_TEST env var#9417

Open
toroleapinc wants to merge 1 commit intoborgbackup:masterfrom
toroleapinc:fix/issue-9414-benchmark-cpu-test-speed
Open

Speed up benchmark cpu tests with _BORG_BENCHMARK_CPU_TEST env var#9417
toroleapinc wants to merge 1 commit intoborgbackup:masterfrom
toroleapinc:fix/issue-9414-benchmark-cpu-test-speed

Conversation

@toroleapinc
Copy link

Summary

test_benchmark_cpu and test_benchmark_cpu_json are slow because they run the full borg benchmark cpu command with production-grade iteration counts (100 iterations of timeit for most operations, 5 for KDFs, 10MB random data buffer).

Changes

Following the existing pattern of _BORG_BENCHMARK_CRUD_TEST, this PR adds a _BORG_BENCHMARK_CPU_TEST environment variable that reduces:

  • timeit iterations: 100 → 1 (10 → 1 for compression)
  • KDF iterations: 5 → 1
  • random data buffer: 10MB → 100KB

The tests now set this env var via monkeypatch.setenv, making them complete quickly in CI while still exercising the full benchmark code path (all algorithms, all output formats).

Fixes #9414

Add _BORG_BENCHMARK_CPU_TEST environment variable (following the existing
pattern of _BORG_BENCHMARK_CRUD_TEST) that reduces:
- timeit iterations from 100 to 1 (10 to 1 for compression)
- KDF iterations from 5 to 1
- random data buffer from 10MB to 100KB

Set this env var in test_benchmark_cpu and test_benchmark_cpu_json so
they complete quickly in CI while still exercising the full code path.

Fixes borgbackup#9414

Signed-off-by: edvatar <88481784+toroleapinc@users.noreply.github.com>
Copy link
Member

@ThomasWaldmann ThomasWaldmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR, looks good, just one minor consistency fix please.

else:
result["kdf"] = []
count = 5
count = 1 if is_test else 5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename to number_kdf and move the line close to the others.

@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.48%. Comparing base (0b05b44) to head (bb2ca29).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #9417   +/-   ##
=======================================
  Coverage   76.47%   76.48%           
=======================================
  Files          85       85           
  Lines       14803    14807    +4     
  Branches     2213     2213           
=======================================
+ Hits        11321    11325    +4     
  Misses       2803     2803           
  Partials      679      679           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test_benchmark_cpu_json is slow

2 participants