Skip to content

Commit

Permalink
Add a benchmark for basic performance of memoised methods
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrudy committed Jan 3, 2016
1 parent 421a957 commit 698f16d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/memoist.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'memoist/version'
require 'memoist/core_ext/singleton_class'

module Memoist
Expand Down
1 change: 1 addition & 0 deletions memoist.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_development_dependency "benchmark-ips"
spec.add_development_dependency "bundler"
spec.add_development_dependency "rake"
spec.add_development_dependency "minitest", "~> 5.5.1"
Expand Down
48 changes: 48 additions & 0 deletions script/benchmark.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
$:.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

0 comments on commit 698f16d

Please sign in to comment.