Repository navigation
Integer#** in C#; Range#include? of one-character String ranges in C# - #118
Merged
Merged
Conversation
('a'..'z').include?("m") took ~1 us: the prelude's __string_include__
already compares the bytes for one-character ASCII endpoints, but only
after #__linear__/#__integerish__ and a few more calls. RangeOps answers
it directly now: 1068 -> 182 ns (CRuby ~185).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPwZf7MsYwQdhLBCZCkH2C
… or Complex (#89) rational.rb's `def **` sat in front of every Integer power, so 3 ** 5 cost ~140 ns and 3 ** 0.5 ~290 (CRuby ~13 and ~21). The C# Integer#** (ClrInteger.Power, ClrBigInteger.Power) is the method again and hands rational.rb's __ir_pow_slow__ only a negative exponent (a Rational), a negative base to a fractional power (a Complex) and what has to be coerced; 0 ** NaN is 0.0 there, as in MRI. Without the prelude the CLR answers stand. 3 ** 5 139 -> JIT intrinsic 3 ** 40 367 -> 189 ns (CRuby 173) 3 ** 0.5 287 -> 33 ns (CRuby 21) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KPwZf7MsYwQdhLBCZCkH2C
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 10 minutes. View limit details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR covers two more #89 items after #117. Figures are Release builds on Linux, net8.0, compared against CRuby 4.0.
1.
Integer#**(cf1e069)rational.rb'sdef **sat in front of every Integer power. The C#Integer#**(ClrInteger.Power,ClrBigInteger.Power) is the method again. It handsrational.rb's__ir_pow_slow__(now private) only three cases:Without the prelude, the CLR answers stand, as before.
0 ** NaNis now0.0, as in MRI, whereMath.Powgives NaN.3 ** 53 ** 403 ** 0.53 ** -23 ** -2is still slow: nearly all of it is building the Rational inrational.rb.2.
('a'..'z').include?("m")(5b879eb)When both endpoints are one-character ASCII Strings,
include?is a byte comparison. The prelude's__string_include__already took that shortcut, but only after ~1 µs of other calls to get there.RangeOps.Includenow answers it directly: 1068 → 182 ns (CRuby ~185).Testing
Integer_Power1takes its expected output from CRuby. It covers Rational and Complex results, coercion,0 ** NaN, Bignum exponents andpow.Range_MinMaxInclude1gains the one-character cases.core/complex,core/float,core/numeric,core/kernel,language,core/range,core/string/upto_spec.rb,library/bigdecimal,library/matrix,library/prime.core/integer(15) andcore/rational(4) have the same counts as master. They come from mspec'sfixnum_max()/fixnum_min()helper.Still open from #89
Complex(1, 2)takes ~2 µs andc * c~4 µs, because every object goes throughrational.rbandcomplex.rb.Range#%and#stepwithout a block still take ~2 µs. Most of that is building the Enumerator.Generated by Claude Code