| 1 |
require 'benchmark' |
|---|
| 2 |
|
|---|
| 3 |
messages = Message.find :all |
|---|
| 4 |
n = 10000 |
|---|
| 5 |
|
|---|
| 6 |
puts "Before patching..\n" |
|---|
| 7 |
|
|---|
| 8 |
Benchmark.bm do |x| |
|---|
| 9 |
|
|---|
| 10 |
x.report { n.times { messages.map{|m| m.sender} } } |
|---|
| 11 |
x.report { n.times { messages.map(&:sender) } } |
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
x.report { n.times { messages.map{|m| m.id} } } |
|---|
| 15 |
x.report { n.times { messages.map(&:id) } } |
|---|
| 16 |
end |
|---|
| 17 |
|
|---|
| 18 |
class Symbol |
|---|
| 19 |
def to_proc |
|---|
| 20 |
lambda { |obj| obj.send self } |
|---|
| 21 |
end |
|---|
| 22 |
end |
|---|
| 23 |
|
|---|
| 24 |
puts "After patching..\n" |
|---|
| 25 |
|
|---|
| 26 |
Benchmark.bm do |x| |
|---|
| 27 |
|
|---|
| 28 |
x.report { n.times { messages.map{|m| m.sender} } } |
|---|
| 29 |
x.report { n.times { messages.map(&:sender) } } |
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
x.report { n.times { messages.map{|m| m.id} } } |
|---|
| 33 |
x.report { n.times { messages.map(&:id) } } |
|---|
| 34 |
end |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|