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.
- checksums.yaml +4 -4
- data/lib/simple_bench.rb +34 -20
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 97838becb4bf9bdcaf07255dd405521f7418749605f542a9c14ccafa7b8d904c
|
4
|
+
data.tar.gz: 8f7f9dbd6c9b6500b5b3bc9208b759210c53429dfa021d1b4ce5e41f68f0fe7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5acc7c69c5b8578416420f227ea75fac8619bf926ace11e02d27bd22e0dfd647d7cb449ff3e582e2f6b59c59bdafea07ee661dbb0c44248f67b1674b643f0c19
|
7
|
+
data.tar.gz: a4852ff585ff7f429e5fb5ef357d97411ad37846bc4a308ecb40921c9f0763a8325ead0afaf8caee6786ec9fdce9399b97241fdc0eb4297ff9e16a9f66803624
|
data/lib/simple_bench.rb
CHANGED
@@ -1,37 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Implementation of SimpleBench gem
|
1
4
|
module SimpleBench
|
2
5
|
class << self
|
3
|
-
|
6
|
+
# Expects Strings. Runs each method once.
|
7
|
+
def simple(*methods)
|
4
8
|
Benchmark.bmbm do |x|
|
5
|
-
|
6
|
-
|
9
|
+
methods.each do |method|
|
10
|
+
x.report("#{method}_once") { send(method) }
|
11
|
+
end
|
7
12
|
end
|
8
13
|
end
|
9
14
|
|
10
|
-
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
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
|
-
|
22
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
36
|
+
tiers.each do |tier|
|
37
|
+
run_multiple_times(x, tier, methods)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
27
41
|
|
28
|
-
|
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
|
-
|
33
|
-
|
34
|
-
x.report("#{
|
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:
|
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-
|
11
|
+
date: 2019-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|