Add benchmark for #flat_map
Calculating ------------------------------------- .map.flatten with nested arrays 4718 i/100ms .flat_map with nested arrays 6048 i/100ms .map.flatten with no nested arrays 9804 i/100ms .flat_map with no nested arrays 9302 i/100ms ------------------------------------------------- .map.flatten with nested arrays 48118.3 (±4.8%) i/s - 240618 in 5.011942s .flat_map with nested arrays 63838.6 (±5.1%) i/s - 320544 in 5.034864s .map.flatten with no nested arrays 104879.3 (±4.4%) i/s - 529416 in 5.057802s .flat_map with no nested arrays 99935.3 (±6.6%) i/s - 502308 in 5.049506s
This commit is contained in:
parent
7c05312d5c
commit
a30498ba42
|
@ -0,0 +1,17 @@
|
||||||
|
require 'benchmark/ips'
|
||||||
|
|
||||||
|
enum = (0..50).to_a
|
||||||
|
nested = enum.map { |i| [i] }
|
||||||
|
|
||||||
|
def do_thing(blah)
|
||||||
|
blah * 1
|
||||||
|
end
|
||||||
|
|
||||||
|
Benchmark.ips do |x|
|
||||||
|
x.report('.map.flatten with nested arrays') { nested.map { |i| do_thing(i) }.flatten(1) }
|
||||||
|
x.report('.flat_map with nested arrays') { nested.flat_map { |i| do_thing(i) } }
|
||||||
|
|
||||||
|
x.report('.map.flatten with no nested arrays') { enum.map { |i| do_thing(i) }.flatten(1) }
|
||||||
|
x.report('.flat_map with no nested arrays') { enum.flat_map { |i| do_thing(i) } }
|
||||||
|
end
|
||||||
|
|
Loading…
Reference in New Issue