Open ilyazub opened 1 year ago
@JuanVqz @etagwerker what do you think about a benchmark for String#count
vs String#lines.count
vs String#each_line.count
?
This seems a Rails related benchmark, I wonder if we are adding framework-related benchmarks
It doesn't depend on Rails (https://github.com/ruby/ruby/pull/4001#issuecomment-1715783493). 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 $/
is bad - it's less obvious than "\n"
. More than that, $/
can be redefined, so the code may become broken.
@ixti Sounds good. The performance difference is in the String#count
vs other methods. $/
vs \n
did't impact performance here.
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