Hi all.
What do you think about this changes
https://github.com/rails/rails/compare/master...lvl0nax:am_refactoring?expand=1
Benchmark points
1) gsub => chomp
str = 'some_test'
Benchmark.ips do |x|
x.report("chomp") { str.chomp('_test') }
x.report("gsub") { str.gsub(/_test$/, '') }
x.compare!
end
Calculating -------------------------------------
chomp 135.882k i/100ms
gsub 39.913k i/100ms
-------------------------------------------------
chomp 5.380M (± 1.3%) i/s - 26.905M
gsub 701.756k (± 1.2%) i/s - 3.512M
Comparison:
chomp: 5379548.9 i/s
gsub: 701756.2 i/s - 7.67x slower
2)
def convert_to_reader_name(str)
attr_name = str.to_s
if attr_name.end_with?("=")
attr_name = attr_name[0..-2]
end
attr_name
end
def convert_to_reader_name2(str)
attr_name = str.to_s
attr_name.chomp!('=')
attr_name
end
Benchmark.ips do |x|
x.report("convert_to_reader_name") { convert_to_reader_name(:some_attr=) }
x.report("convert_to_reader_name2") {
convert_to_reader_name2(:some_attr=) }
x.compare!
end
Calculating -------------------------------------
convert_to_reader_name 92.102k i/100ms
convert_to_reader_name2 104.351k i/100ms
-------------------------------------------------
convert_to_reader_name 2.432M (± 2.0%) i/s - 12.157M
convert_to_reader_name2 3.302M (± 2.2%) i/s - 16.592M
Comparison:
convert_to_reader_name2: 3301787.5 i/s
convert_to_reader_name: 2432453.5 i/s - 1.36x slower
3) sub => chomp
str = 'some_test'
Benchmark.ips do |x|
x.report("chomp") { str.chomp('_test') }
x.report("sub") { str.sub(/_test$/, '') }
x.compare!
end
Calculating -------------------------------------
chomp 142.856k i/100ms
sub 63.737k i/100ms
-------------------------------------------------
chomp 5.273M (± 1.6%) i/s - 26.428M
sub 1.680M (± 1.3%) i/s - 8.413M
Comparison:
chomp: 5273308.8 i/s
sub: 1680494.3 i/s - 3.14x slower
If you think it's OK, I will fix it and continue
Regards, Dmitry.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.