Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept String as a pattern #4

Merged
merged 1 commit into from Apr 18, 2019

Conversation

1 participant
@kou
Copy link
Member

commented Apr 4, 2019

It's only for head only match case such as StringScanner#scan.

If we use a String as a pattern, we can improve match performance.
Here is a result of the including benchmark. It shows String as a
pattern is 1.25x faster than Regexp as a pattern.

% rake benchmark
/tmp/local/bin/ruby -S benchmark-driver benchmark/scan.yaml
Warming up --------------------------------------
              regexp    12.094M i/s -     12.242M times in 1.012250s (82.69ns/i, 277clocks/i)
              string    14.653M i/s -     14.889M times in 1.016124s (68.25ns/i, 252clocks/i)
Calculating -------------------------------------
              regexp    14.713M i/s -     36.281M times in 2.465970s (67.97ns/i, 254clocks/i)
              string    18.422M i/s -     43.959M times in 2.386255s (54.28ns/i, 201clocks/i)

Comparison:
              string:  18421631.8 i/s
              regexp:  14712660.7 i/s - 1.25x  slower
Accept String as a pattern
It's only for head only match case such as StringScanner#scan.

If we use a String as a pattern, we can improve match performance.
Here is a result of the including benchmark. It shows String as a
pattern is 1.25x faster than Regexp as a pattern.

    % rake benchmark
    /tmp/local/bin/ruby -S benchmark-driver benchmark/scan.yaml
    Warming up --------------------------------------
                  regexp    12.094M i/s -     12.242M times in 1.012250s (82.69ns/i, 277clocks/i)
                  string    14.653M i/s -     14.889M times in 1.016124s (68.25ns/i, 252clocks/i)
    Calculating -------------------------------------
                  regexp    14.713M i/s -     36.281M times in 2.465970s (67.97ns/i, 254clocks/i)
                  string    18.422M i/s -     43.959M times in 2.386255s (54.28ns/i, 201clocks/i)

    Comparison:
                  string:  18421631.8 i/s
                  regexp:  14712660.7 i/s - 1.25x  slower

kou added a commit to ruby/csv that referenced this pull request Apr 4, 2019

@kou kou merged commit 4959c97 into ruby:master Apr 18, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@kou kou deleted the kou:accept-string-as-a-pattern branch Apr 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.