aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
authorBenjamin Quorning <bquorning@zendesk.com>2015-08-02 13:01:03 +0200
committerBenjamin Quorning <bquorning@zendesk.com>2015-08-02 14:31:07 +0200
commitd531edc829101d9969273f7f0f920c05000d6e62 (patch)
tree9526008d499969b9587670095fffeecd91b386c7 /activejob/lib
parent13beb92a1ee189b64d3121213b7b8fcbf25a60ea (diff)
downloadrails-d531edc829101d9969273f7f0f920c05000d6e62.tar.gz
rails-d531edc829101d9969273f7f0f920c05000d6e62.tar.bz2
rails-d531edc829101d9969273f7f0f920c05000d6e62.zip
Save a string allocation inside loop
In the `tag_options` method, strings are continuously added to the `output` string. Previously, we concatenated two strings and added the generated string to `output`. By adding each of the strings to `output`, one after the other, we will save the allocation of that concatenated string. Benchmark: require 'benchmark/ips' sep = " ".freeze Benchmark.ips do |x| x.report("string +") { output = "" output << sep + "foo" } x.report("string <<") { output = "" output << sep output << "foo" } x.compare! end Results (Ruby 2.2.2): Calculating ------------------------------------- string + 88.086k i/100ms string << 94.287k i/100ms ------------------------------------------------- string + 2.407M (± 5.8%) i/s - 12.068M string << 2.591M (± 7.0%) i/s - 12.917M Comparison: string <<: 2591482.4 i/s string +: 2406883.7 i/s - 1.08x slower
Diffstat (limited to 'activejob/lib')
0 files changed, 0 insertions, 0 deletions