forked from drapergem/draper
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbechmark.rb
55 lines (48 loc) · 1.44 KB
/
bechmark.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'rubygems'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Bundler.require(:default) if defined?(Bundler)
require "benchmark"
require "draper"
require "./performance/models"
require "./performance/decorators"
Benchmark.bm do |bm|
puts "\n[ Exclusivelly using #method_missing for model delegation ]"
[ 1_000, 10_000, 100_000 ].each do |i|
puts "\n[ #{i} ]"
bm.report("#new ") do
i.times do |n|
ProductDecorator.decorate(Product.new)
end
end
bm.report("#hello_world ") do
i.times do |n|
ProductDecorator.decorate(Product.new).hello_world
end
end
bm.report("#sample_class_method ") do
i.times do |n|
ProductDecorator.decorate(Product.new).class.sample_class_method
end
end
end
puts "\n[ Defining methods on method_missing first hit ]"
[ 1_000, 10_000, 100_000 ].each do |i|
puts "\n[ #{i} ]"
bm.report("#new ") do
i.times do |n|
FastProductDecorator.decorate(FastProduct.new)
end
end
bm.report("#hello_world ") do
i.times do |n|
FastProductDecorator.decorate(FastProduct.new).hello_world
end
end
bm.report("#sample_class_method ") do
i.times do |n|
FastProductDecorator.decorate(FastProduct.new).class.sample_class_method
end
end
end
end