Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #8812: perform.rb

File perform.rb, 0.6 kB (added by lifofifo, 2 years ago)
Line 
1 require 'benchmark'
2
3 messages = Message.find :all # 800 records
4 n = 10000
5
6 Benchmark.bm do |x|
7   # String
8   x.report { n.times { messages.map{|m| m.sender} } }
9   x.report { n.times { messages.map(&:sender) } }
10  
11   # Integer
12   x.report { n.times { messages.map{|m| m.id} } }
13   x.report { n.times { messages.map(&:id) } }
14 end
15
16 # $ script/runner perform.rb
17 #       user     system      total        real
18 #  10.750000   0.080000  10.830000 ( 11.295768)
19 #  76.270000   0.530000  76.800000 ( 80.127644)
20 #   9.710000   0.050000   9.760000 (  9.911562)
21 #  75.210000   0.450000  75.660000 ( 77.835031)