Skip to content

Instantly share code, notes, and snippets.

class A < Struct.new(:a, :b)
end
B = Struct.new(:a, :b)
require 'benchmark'
Benchmark.bmbm 20 do |r|
n = 10_000_000
a = A.new(1,2)
require "benchmark"
def f(i); i; end
array = Array.new(1_000_000) { rand.to_s }
TESTS = 5
Benchmark.bmbm do |results|
results.report("null:") { TESTS.times { array.each { |i| f(i) } } }
results.report("sliced each:") { TESTS.times { array[1,array.size-2].each { |i| f(i) } } }