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
|
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'benchmark/ips'
require 'memoist'
class Benchy
extend Memoist
def arity_0
'Hello World'
end
memoize :arity_0
def arity_1(name)
"Hello #{name}"
end
memoize :arity_1
end
OBJECT = Benchy.new
puts "Benchmarking: #{Memoist::VERSION}"
Benchmark.ips do |x|
x.report('arity 0 - memoized') do |times|
times.times do
OBJECT.arity_0
end
end
# x.report("arity 0 - unmemoized") do |times|
# times.times do
# OBJECT._unmemoized_arity_0
# end
# end
x.report('arity 1 - memoized') do |times|
times.times do
OBJECT.arity_1(:World)
end
end
# x.report("arity 1 - unmemoized") do |times|
# times.times do
# OBJECT._unmemoized_arity_1(:World)
# end
# end
end
|