Sha256: 0191df36b979654b7d5983f28d048a6eb5eeb5c7c454465017786048b599ef6c
Contents?: true
Size: 482 Bytes
Versions: 13
Compression:
Stored size: 482 Bytes
Contents
#!/usr/bin/env ruby require 'benchmark' class Thing attr_reader :part def initialize(part) @part = part end end prng = Random.new v_max = 1 << 31 ary = [] 1000.times do ary << Thing.new(rand(v_max)) end Benchmark.bmbm do |x| x.report("sort!") do 1000.times do ary2 = ary.dup ary2.sort! { |a, b| a.part <=> b.part } end end x.report("sort_by!") do 1000.times do ary2 = ary.dup ary2.sort_by! { |i| i.part } end end end
Version data entries
13 entries across 13 versions & 1 rubygems