1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-31 19:39:39 +00:00
Holger Just f8d8c040d5 Optimize the TruncateMessage filter with Proc selectors
If we have a proc, we can pass it directly to the `select!` method
instead of having to manually call the selector. This gives a
significant speedup for the common case of simple selectors:

    require 'benchmark/ips'
    Benchmark.ips do |x|
      selector = ->(value) { value < 500 }
      values = (1..1000).to_a

      x.report("call") { values.select { |v| selector.call(v) } }
      x.report("block") { values.select(&selector) }

      x.compare!
    end

    Warming up --------------------------------------
                    call   663.000  i/100ms
                   block     1.598k i/100ms
    Calculating -------------------------------------
                    call      6.897k (± 4.8%) i/s -     34.476k in   5.011617s
                   block     16.561k (± 4.2%) i/s -     83.096k in   5.026999s

    Comparison:
                   block:    16560.7 i/s
                    call:     6896.5 i/s - 2.40x  slower
2017-09-23 01:16:27 +02:00
..