simple_bench 0.0.2 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/simple_bench.rb +34 -20
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b5766678c0d0e97edb764da9c92da8bad21133ca91cc9ba9305f62358957e6c
4
- data.tar.gz: 32714d75da244b3365d19444f7fd522e1d682a33d3098a5dc56f13aea6b99031
3
+ metadata.gz: 97838becb4bf9bdcaf07255dd405521f7418749605f542a9c14ccafa7b8d904c
4
+ data.tar.gz: 8f7f9dbd6c9b6500b5b3bc9208b759210c53429dfa021d1b4ce5e41f68f0fe7c
5
5
  SHA512:
6
- metadata.gz: 2b57094fba860e87127c698a5fb81b447e486cbf8c3cde26cddd16b95972057b69036205daddf9a004ade87e84123627bf35e5f9761ded7ee53e7e4958b450d3
7
- data.tar.gz: 764c5dea84fa64a8b204a1689209b1e167aff3ae325ce99bb42877b42683f652f3acb858e5d14aed91365ae264f0537244ae14b010ad214f0a4657d93f6f8d57
6
+ metadata.gz: 5acc7c69c5b8578416420f227ea75fac8619bf926ace11e02d27bd22e0dfd647d7cb449ff3e582e2f6b59c59bdafea07ee661dbb0c44248f67b1674b643f0c19
7
+ data.tar.gz: a4852ff585ff7f429e5fb5ef357d97411ad37846bc4a308ecb40921c9f0763a8325ead0afaf8caee6786ec9fdce9399b97241fdc0eb4297ff9e16a9f66803624
@@ -1,37 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Implementation of SimpleBench gem
1
4
  module SimpleBench
2
5
  class << self
3
- def simple(method_1, method_2)
6
+ # Expects Strings. Runs each method once.
7
+ def simple(*methods)
4
8
  Benchmark.bmbm do |x|
5
- x.report("#{method_1}_once") { send(method_1) }
6
- x.report("#{method_2}_once") { send(method_2) }
9
+ methods.each do |method|
10
+ x.report("#{method}_once") { send(method) }
11
+ end
7
12
  end
8
13
  end
9
14
 
10
- def n_times(method_1, method_2, n)
15
+ # Expects Strings. Runs each method once, and then as many times as specified
16
+ def n_times(*methods, number_of_times)
11
17
  Benchmark.bmbm do |x|
12
- x.report("#{method_1}_once") { send(method_1) }
13
- x.report("#{method_2}_once") { send(method_2) }
14
- x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
15
- x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }
18
+ methods.each do |method|
19
+ x.report("#{method}_once") { send(method) }
20
+ end
21
+
22
+ run_multiple_times(x, number_of_times, methods)
16
23
  end
17
24
  end
18
25
 
19
- def tiered(method_1, method_2)
26
+ # Expects Strings. Runs each method once, and then 1_000 times, 20_000 times,
27
+ # and 75_000 times
28
+ def tiered(*methods)
20
29
  Benchmark.bmbm do |x|
21
- x.report("#{method_1}_once") { send(method_1) }
22
- x.report("#{method_2}_once") { send(method_2) }
30
+ tiers = [1_000, 20_000, 75_000]
31
+
32
+ methods.each do |method|
33
+ x.report("#{method}_once") { send(method) }
34
+ end
23
35
 
24
- n = 1_000
25
- x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
26
- x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }
36
+ tiers.each do |tier|
37
+ run_multiple_times(x, tier, methods)
38
+ end
39
+ end
40
+ end
27
41
 
28
- n = 10_000
29
- x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
30
- x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }
42
+ private
31
43
 
32
- n = 100_000
33
- x.report("#{method_1}_#{n}_times") { n.times { send(method_1) } }
34
- x.report("#{method_2}_#{n}_times") { n.times { send(method_2) } }
44
+ def run_multiple_times(x, number_of_times, methods)
45
+ methods.each do |method|
46
+ x.report("#{method}_#{number_of_times}_times") do
47
+ number_of_times.times { send(method) }
48
+ end
35
49
  end
36
50
  end
37
51
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_bench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Clive Corbishley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: