Skip to content

Turn pbench into a performance regression test - #186

Merged
danielpclark merged 2 commits into
masterfrom
claude/determined-shannon-ybz9nf-pbench-regressions
Oct 4, 2026
Merged

danielpclark merged 2 commits into
masterfrom
claude/determined-shannon-ybz9nf-pbench-regressions

Conversation

@danielpclark

Copy link
Copy Markdown
Owner

Closes #61.

What

  • test/pbench/pbench_suite.rb: every benchmark gets a min: floor, the least improvement over Ruby (in percent) the method must keep. The suite now ends in a Minitest::Test that runs the benchmarks and fails when any method measures below its floor, so rake pbench, and therefore rake test and CI, go red on a performance regression instead of only printing a number.
  • test/pbench/pbench.rb: run returns the results, and a new regressions method compares them with the floors.
  • lib/faster_path.rb: FasterPath.ruby_arch_bits measures the pointer width instead of 1.size (the width of a C long, 4 bytes on 64-bit Windows), which made the pbench header on Windows CI read "32-bit ruby" for a 64-bit Ruby. test/arch_bits_test.rb checks the Ruby and Rust sides agree.
  • README.md: a paragraph in "Benchmarks" explaining the floors.

The floors

About half of the improvements documented in the README, so the noise of a shared CI runner doesn't trip them but a method falling back towards Ruby's speed does:

Method Floor Lowest seen in CI (Linux/macOS)
absolute?, cleanpath_aggressive, cleanpath_conservative, plus, relative?, relative_path_from 80% 89.6%
has_trailing_separator? 75% 88.0%
del_trailing_separator, join 70% 83.0%
add_trailing_separator, chop_basename, extname 50% 66.7%
dirname 30% 54.2%
basename 15% 29.8%
children, directory?, entries (filesystem-bound) 0% 12.7%
children_compat, entries_compat, allocate baseline none entries_compat measured -2.5% once

On Windows the floors are reported but not enforced (the test skips with the list of regressions), because join is currently slower than Ruby's own there, see #185. Once that is fixed the skip can go.

Verification

With Ruby 2.7.8 on Linux: bundle exec rake pbench passes (1 test, all methods above their floors, output unchanged apart from the test summary). Temporarily setting dirname's floor to 200% makes the task fail with:

Performance regressions:
  dirname is 39.6% faster than Ruby, below its floor of 200%

TEST_MONKEYPATCHES=true WITH_REGRESSION=true ENCODING=true bundle exec rake minitest lint passes (132 tests, 72 files inspected, no offenses).

🤖 Generated with Claude Code

https://claude.ai/code/session_01CXvfgWzuq28ewqT3AyhX4Z


Generated by Claude Code

danielpclark and others added 2 commits October 4, 2026 19:59
`FasterPath.ruby_arch_bits` used `1.size`, the width of a C `long`, which
is 4 bytes on 64-bit Windows, so the pbench header there read "32-bit ruby"
for a 64-bit Ruby. The pointer width is what the Rust side measures too, so
the two now agree, and a test checks that they do.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CXvfgWzuq28ewqT3AyhX4Z
Each benchmark in the pbench suite gets a `min:` floor, the least
improvement over Ruby the method must keep, and `rake pbench` now runs as
a minitest test that fails when a method measures below it. Since
`rake test` includes pbench, a change that makes a method slower now shows
up in CI instead of only in a number nobody compares.

The floors are about half of the improvements documented in the README,
so that the noise of a shared CI runner doesn't trip them but a method
falling back towards Ruby's speed does. The methods that mostly wait on
the filesystem (children, directory?, entries) only have to stay faster
than Ruby, and the _compat methods and the allocate baseline have no
floor. On Windows, where join is currently slower than Ruby's own (#185),
regressions are reported as a skip rather than enforced.

Closes #61

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CXvfgWzuq28ewqT3AyhX4Z
@semanticdiff-com

Copy link
Copy Markdown

Review changes with  SemanticDiff

@danielpclark
danielpclark merged commit a3c4d67 into master Oct 4, 2026
20 checks passed
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.

Add regression tests

1 participant