-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a benchmark for basic performance of memoised methods
- Loading branch information
1 parent
421a957
commit 698f16d
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |