-
Notifications
You must be signed in to change notification settings - Fork 13
/
benchmark.rb
62 lines (47 loc) · 930 Bytes
/
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
# frozen_string_literal: true
require "bundler/setup"
Bundler.setup
require "benchmark"
require "benchmark/ips"
require "benchmark/memory"
puts "```ruby"
puts File.read(__FILE__)
puts "```"
puts
puts "### Output"
puts
puts "```"
require_relative "lib/memery"
class Foo
class << self
include Memery
def base_find(char)
("a".."k").find { |letter| letter == char }
end
memoize def find_z
base_find("z")
end
memoize def find_new(char)
base_find(char)
end
end
end
def test_no_args
Foo.find_z
end
def test_with_args
Foo.find_new("d")
end
Benchmark.ips do |x|
x.report("test_no_args") { test_no_args }
end
Benchmark.memory do |x|
x.report("test_no_args") { 100.times { test_no_args } }
end
Benchmark.ips do |x|
x.report("test_with_args") { test_with_args }
end
Benchmark.memory do |x|
x.report("test_with_args") { 100.times { test_with_args } }
end
puts "```"