All pastes #563302 Raw Edit

Stuff

public ruby v1 · immutable
·published 2007-06-13 02:27 UTC
rendered paste body
require 'benchmark'id_list = (1..1_000_000).to_aBenchmark::bmbm do |x|    x.report("inject")   { id_list.inject({})      { |a,e| a[e] = e.object_id ; a} }    x.report("zip")      { Hash[ *id_list.zip(id_list.collect {|e| e.object_id})] }    x.report("non-bang") { Hash[ *id_list.collect  { |e| [e,e.object_id]}.flatten] }    x.report("bang")     { Hash[ *id_list.collect  { |e| [e,e.object_id]}.flatten!] }    x.report("two-bang") { Hash[ *id_list.collect! { |e| [e,e.object_id]}.flatten!] }end