Sha256: 0c87a087885b5c5cd64c32855972c146356ec8a2d235d6a2f2e89725c14458bf
Contents?: true
Size: 546 Bytes
Versions: 26
Compression:
Stored size: 546 Bytes
Contents
#!/usr/bin/env ruby # frozen_string_literal: true 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
Version data entries
26 entries across 26 versions & 1 rubygems