File: benchmark.rb

package info (click to toggle)
ruby-memoist 0.16.2-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 180 kB
  • sloc: ruby: 616; sh: 4; makefile: 3
file content (48 lines) | stat: -rw-r--r-- 822 bytes parent folder | download | duplicates (3)
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