-
Notifications
You must be signed in to change notification settings - Fork 377
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
str.count("\n")
is 1.3-170 times faster than str.lines.count
or str.each_line.count
depending on the string size
#220
Comments
@JuanVqz @etagwerker what do you think about a benchmark for |
This seems a Rails related benchmark, I wonder if we are adding framework-related benchmarks |
It doesn't depend on Rails (ruby/ruby#4001 (comment)). I updated the benchmark code to work with the plain Ruby. |
@JuanVqz I updated the benchmark code above to work with the plain Ruby. What do you think? |
IMHO using |
str.count($/)
is 1.3x faster than str.lines.count
or str.each_line.count
str.count("\n")
is 1.3x faster than str.lines.count
or str.each_line.count
@ixti Sounds good. The performance difference is in the |
str.count("\n")
is 1.3x faster than str.lines.count
or str.each_line.count
str.count("\n")
is 1.3-170 times faster than str.lines.count
or str.each_line.count
depending on the string size
str.count("\n")
is 1.3-170 times faster thanstr.lines.count
orstr.each_line.count
(ref: https://serpapi.com/blog/lines-count-failed-deployments/). The speed difference grows with the lines count.Benchmark code:
I'd like to add this benchmark to
fast-ruby
. Wdyt?Based on our updates to the @guilhermesimoes' very helpful gist: https://gist.github.com/guilhermesimoes/d69e547884e556c3dc95?permalink_comment_id=4687645#gistcomment-4687645
The text was updated successfully, but these errors were encountered: