Skip to content

Commit b264f61

Browse files
committed
Add a benchmark suite
Add a benchmark that measures the time it takes to delegate to the view context.
1 parent 0c8d8d4 commit b264f61

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ platform :ruby do
99
gem 'github-markup'
1010
gem 'rails', '~> 4.2.0', require: false
1111
gem 'rspec-rails', require: false
12+
gem 'benchmark-ips', require: false
1213
end

perf/component_benchmark.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
require 'bundler/setup'
2+
require 'benchmark/ips'
3+
4+
ENV["RAILS_ENV"] = "test"
5+
6+
require_relative '../spec/dummy/config/environment'
7+
8+
class TestPresenter < Curly::Presenter
9+
def hello_with_delegation
10+
some_helper
11+
end
12+
13+
def hello_without_delegation
14+
not_some_helper
15+
end
16+
17+
private
18+
19+
def not_some_helper
20+
end
21+
end
22+
23+
class TestContext
24+
def some_helper
25+
end
26+
end
27+
28+
context = TestContext.new
29+
presenter = TestPresenter.new(context)
30+
31+
Benchmark.ips do |x|
32+
x.report "presenter method that delegates to the view context" do
33+
presenter.hello_with_delegation
34+
end
35+
36+
x.report "presenter method that doesn't delegate to the view context" do
37+
presenter.hello_without_delegation
38+
end
39+
40+
x.compare!
41+
end

0 commit comments

Comments
 (0)