1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionview/lib
Benjamin Quorning d531edc829 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
2015-08-02 14:31:07 +02:00
..
action_view Save a string allocation inside loop 2015-08-02 14:31:07 +02:00
action_view.rb Update copyright notices to 2015 [ci skip] 2014-12-31 08:34:14 +01:00