, 나는 들어, 값을 수집 할 때 당신이 performance
이득을 가질 수를 추가 할 것 예 :
require 'benchmark'
members_without_sym = {"total"=>3, "data"=>[
{"email"=>"[email protected]", "timestamp"=>"2013-03-16 01:11:01"},
{"email"=>"[email protected]", "timestamp"=>"2013-03-16 02:07:30"},
{"email"=>"[email protected]", "timestamp"=>"2013-03-16 03:06:24"}
]}
members_with_sym = {:total=>3, :data=>[
{:email=> "[email protected]", :timestamp => "2013-03-16 01:11:01"},
{:email=> "[email protected]", :timestamp => "2013-03-16 02:07:30"},
{:email=> "[email protected]", :timestamp=> "2013-03-16 03:06:24"}
]}
Benchmark.bm(1) do |algo|
algo.report("Without symbol"){
2_000_000.times do
members_without_sym['data'].collect { |h| h['email'] }
end
}
algo.report("With symbol"){
2_000_000.times do
members_with_sym[:data].collect { |h| h[:email] }
end
}
end
결과 :
user system total real
Without symbol 2.260000 0.000000 2.260000 ( 2.254277)
With symbol 0.880000 0.000000 0.880000 ( 0.878603)
데이터는 MailChimp API에서 가져온 것입니다. 따라서이 경우 ** 기호 **를 활용할 수 없습니다. 어쨌든 +1 – user569825