-
Notifications
You must be signed in to change notification settings - Fork 10
/
around_advice_benchmark.rb
65 lines (53 loc) · 1.02 KB
/
around_advice_benchmark.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
56
57
58
59
60
61
62
63
64
class A
def test input
input.upcase!
end
end
class B
def test input
input.upcase!
end
end
##############################
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'aspector'
class AroundAspect < Aspector::Base
around :test do |*args, &proxy|
begin
proxy.call
rescue => e
end
end
end
class RawAspect < Aspector::Base
target do
wrapped_method = instance_method(:test)
define_method :test do |*args, &block|
begin
wrapped_method.bind(self).call *args, &block
rescue => e
end
end
end
end
##############################
AroundAspect.apply(A)
RawAspect.apply(B)
a = A.new
b = B.new
require 'benchmark'
TIMES = 100000
Benchmark.bmbm do |x|
x.report "Around advice - good" do
TIMES.times { a.test 'good' }
end
x.report "Around advice - bad" do
TIMES.times { a.test nil }
end
x.report "Raw - good" do
TIMES.times { b.test 'good' }
end
x.report "Raw - bad" do
TIMES.times { b.test nil }
end
end