Add is pattern benchmarks - #85027
Conversation
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static bool HasLeadingSlashWithPattern(ReadOnlySpan<char> path) | ||
| { | ||
| if (path.Length > 0 && path[0] is '/' or '\\') |
There was a problem hiding this comment.
📝 I guess the pattern cases will become equivalent to the comparison cases when the compiler used to build these is updated to include the fix, but perhaps these benchmarks are still useful as a sort of regression gate?
There was a problem hiding this comment.
Pull request overview
This PR adds new micro-benchmarks under src/Tools/Benchmarks for small is-pattern scenarios and updates the compiler’s LocalRewriter_IsPatternOperator comment to reference an in-repo benchmark source instead of an external PR link.
Changes:
- Added
IsPatternBenchmarks.cscontaining benchmarks comparing comparison-based implementations vsis-pattern implementations for a few small-pattern scenarios. - Updated the documentation comment for
MaxTestsForInvertedLinearSequenceto point at the new benchmark file.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/Tools/Benchmarks/IsPatternBenchmarks.cs | Introduces new BenchmarkDotNet benchmarks for small is-pattern cases (leading slash and small byte-pattern sets). |
| src/Compilers/CSharp/Portable/Lowering/LocalRewriter/LocalRewriter_IsPatternOperator.cs | Updates the explanatory comment for the inverted-linear-sequence threshold to reference in-repo benchmark code. |
Suppressed comments (1)
src/Tools/Benchmarks/IsPatternBenchmarks.cs:107
- The baseline implementation compares a
byte(Value) tocharliterals. Aligning the baseline with the pattern version by usingbyteconstants makes the comparison more directly about the lowering strategy and avoids implicit integral promotions.
public bool Comparisons() => Guard && (Value == '+' || Value == '.' || Value == 'E' || Value == 'e');
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/Tools/Benchmarks/IsPatternBenchmarks.cs:34
- Avoid the null-forgiving initializer here; the benchmark can start with a non-null default and still be overwritten in GlobalSetup. This removes a nullability suppression and makes the type safe if the benchmark is ever instantiated outside BenchmarkDotNet’s setup flow.
private string _path = null!;
|
Azure Pipelines: Successfully started running 2 pipeline(s). There may be pipelines that require an authorized user to comment /azp run to run. |
Follow up on #84961 (comment).
Results of
IsPatternLeadingSlashBenchmarksMicrosoft Reviewers: Open in CodeFlow