Skip to content

tr: add codspeed benchmark#12189

Open
parasol-aser wants to merge 1 commit intouutils:mainfrom
parasol-aser:tr/codspeed-bench
Open

tr: add codspeed benchmark#12189
parasol-aser wants to merge 1 commit intouutils:mainfrom
parasol-aser:tr/codspeed-bench

Conversation

@parasol-aser
Copy link
Copy Markdown

What

Adds a divan-based benchmark suite at src/uu/tr/benches/tr_bench.rs, registered in .github/workflows/benchmarks.yml so CodSpeed tracks it on every PR.

tr only reads stdin, so each bench redirects fd 0 to a prepared file (and fd 1 to /dev/null) around uumain, mirroring the existing src/uu/tee/benches/tee_bench.rs pattern with rustix.

The suite covers four cases at 1 / 16 / 64 MB inputs:

  • tr_ascii_range_lower_to_uppertr a-z A-Z (range translation)
  • tr_single_char_replacetr a b (single-byte SIMD path)
  • tr_multi_char_translatetr aeiou AEIOU (table-lookup path)
  • tr_delete_ascii_rangetr -d a-z (deletion path)

Why

Requested by @sylvestre in #12118 to provide regression coverage for the tr translation paths and the upcoming AVX2 ASCII-range fast path landing in that PR.

Local invocation

cargo bench -p uu_tr
# or, mirroring CI:
cargo codspeed build -p uu_tr && cargo codspeed run -p uu_tr

Notes

  • Bench code is #[cfg(unix)] because the rustix stdin/stdout redirection is unix-only; on other targets the bench compiles to an empty divan::main().
  • No production source changes — only benches/, Cargo.toml dev-deps, and the workflow matrix.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/date/resolution (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/dd/no-allocate is now being skipped but was previously passing.
Note: The gnu test tests/unexpand/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/env/env-signal-handler was skipped on 'main' but is now failing.

Comment thread src/uu/tr/BENCHMARKING.md Outdated

`tr` performance is critical for large data processing pipelines. The implementation uses lookup tables for O(1) character operations.

## CodSpeed (CI)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 190a973 — removed the CodSpeed section.

Comment thread src/uu/tr/benches/tr_bench.rs Outdated
/// Exercises the AVX2 ASCII-range fast path on x86_64 hosts that
/// support it, and the scalar range fallback on other targets.
#[cfg(unix)]
#[divan::bench(args = [1, 16, 64])]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please test with only one value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done in 190a973 — collapsed to a single 16 MB size (SIZE_MB const) across all four benches.

Adds a divan-based benchmark suite under src/uu/tr/benches/ that
codspeed can build and run, and registers uu_tr in the benchmarks
workflow matrix. Each bench redirects fd 0 to a prepared file and
fd 1 to /dev/null around uumain since tr only reads stdin.

Covers the AVX2 ASCII-range fast path, single-char replace,
multi-char table translation, and ASCII range delete, at 1/16/64 MB.
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.

2 participants