👍 PR welcome. On Sat, May 14, 2016 at 00:14 Dmitry Gautsel <lvl0...@gmail.com> wrote:
> Hi. > > What do you think about these changes: > > #current_behaviourdef ordinal(number) > abs_number = number.to_i.abs > > if (11..13).include?(abs_number % 100) > "th" > else > case abs_number % 10 > when 1; "st" > when 2; "nd" > when 3; "rd" > else "th" > end > endend > #new behaviourdef ordinal2(number) > tmp = number.to_i.abs % 100 > > if 11 <= tmp && tmp <= 13 > "th".freeze > else > case tmp % 10 > when 1; "st".freeze > when 2; "nd".freeze > when 3; "rd".freeze > else "th".freeze > end > endend > Benchmark.ips do |x| > x.report('before') { ordinal(1523) } > x.report('after') { ordinal2(1523) } > x.compare!end > > Calculating ------------------------------------- > before 111.577k i/100ms > after 143.646k i/100ms > ------------------------------------------------- > before 3.395M (± 1.3%) i/s - 17.071M > after 5.088M (± 1.1%) i/s - 25.569M > > Comparison: > after: 5088264.3 i/s > before: 3394612.5 i/s - 1.50x slower > > -- > 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 rubyonrails-core+unsubscr...@googlegroups.com. > To post to this group, send email to rubyonrails-core@googlegroups.com. > Visit this group at https://groups.google.com/group/rubyonrails-core. > For more options, visit https://groups.google.com/d/optout. > -- 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 rubyonrails-core+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-core@googlegroups.com. Visit this group at https://groups.google.com/group/rubyonrails-core. For more options, visit https://groups.google.com/d/optout.