sus-fixtures-benchmark 0.1.0 → 0.2.0
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
- checksums.yaml.gz.sig +0 -0
- data/lib/sus/fixtures/benchmark/repeats.rb +49 -6
- data/lib/sus/fixtures/benchmark/time.rb +1 -1
- data/lib/sus/fixtures/benchmark/version.rb +1 -1
- data/lib/sus/fixtures/benchmark.rb +7 -2
- data/readme.md +4 -0
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91585211a64e9c0976bfb3df369a629697cc777f7fdbf542a4465e20aa546f12
|
4
|
+
data.tar.gz: 2198dc293faa26db8c3e7d200f825debb60c317851185f020e95f743422e034c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88b568301dda12a68ddab43ef83a53bce07506ef050ae1d9649bdbe76a377dc4b847d8543e76355bea556ced03c22d98e2898f36bfeae488844d459125c62f10
|
7
|
+
data.tar.gz: daad4662ef40498501e446211544d931e7af0dc6d9823d2a496292af2659928af96cbe16e74f8a4bc94c07a4c4aa74dcf3e675b28a5bda94947a0500e6b01143
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
#
|
4
3
|
# Released under the MIT License.
|
5
4
|
# Copyright, 2025, by Samuel Williams.
|
6
5
|
|
@@ -12,27 +11,71 @@ module Sus
|
|
12
11
|
# Represents a benchmarking helper that executes a block multiple times, collecting timing samples until statistical convergence is reached.
|
13
12
|
class Repeats
|
14
13
|
# Initializes a new {Repeats} object with a sampler to collect timing data.
|
15
|
-
# @parameter
|
16
|
-
def initialize(
|
17
|
-
@
|
14
|
+
# @parameter sampler [Sampler] The sampler object to collect timing data.
|
15
|
+
def initialize(sampler)
|
16
|
+
@sampler = sampler
|
18
17
|
end
|
19
18
|
|
19
|
+
# @attribute [Sampler] The sampler that collects timing data.
|
20
|
+
attr :sampler
|
21
|
+
|
20
22
|
# Samples the execution time of the given block and adds the result to the sampler.
|
21
23
|
# @parameter block [Proc] The block to benchmark.
|
22
24
|
private def sample!(block)
|
23
25
|
time = Benchmark::Time.measure do
|
24
26
|
block.call
|
25
27
|
end
|
26
|
-
@
|
28
|
+
@sampler.add(time.real)
|
27
29
|
end
|
28
30
|
|
29
31
|
# Repeatedly executes the block until the sampler reports convergence.
|
30
32
|
# @parameter block [Proc] The block to benchmark.
|
31
33
|
def times(&block)
|
32
|
-
until @
|
34
|
+
until @sampler.converged?
|
33
35
|
sample!(block)
|
34
36
|
end
|
35
37
|
end
|
38
|
+
|
39
|
+
# Represents a benchmarking helper that executes a block a fixed number of times.
|
40
|
+
class Exactly
|
41
|
+
# Initializes a new {Exactly} object with a sampler and a fixed count.
|
42
|
+
# @parameter sampler [Sampler] The sampler object to collect timing data.
|
43
|
+
# @parameter count [Integer] The exact number of times to execute the block.
|
44
|
+
def initialize(sampler, count)
|
45
|
+
@sampler = sampler
|
46
|
+
@count = count
|
47
|
+
end
|
48
|
+
|
49
|
+
# @attribute [Sampler] The sampler that collects timing data.
|
50
|
+
attr :sampler
|
51
|
+
|
52
|
+
# @attribute [Integer] The number of times to execute the block.
|
53
|
+
attr :count
|
54
|
+
|
55
|
+
# Samples the execution time of the given block and adds the result to the sampler.
|
56
|
+
# @parameter block [Proc] The block to benchmark.
|
57
|
+
private def sample!(block)
|
58
|
+
time = Benchmark::Time.measure do
|
59
|
+
block.call
|
60
|
+
end
|
61
|
+
@sampler.add(time.real)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Executes the block exactly the specified number of times.
|
65
|
+
# @parameter block [Proc] The block to benchmark.
|
66
|
+
def times(&block)
|
67
|
+
@count.times do
|
68
|
+
sample!(block)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# Sets a fixed number of times to execute the block, returning a new {Exactly} instance.
|
74
|
+
# @parameter count [Integer] The exact number of times to execute the block.
|
75
|
+
# @returns [Exactly] A new instance that will execute the block exactly the specified number of times.
|
76
|
+
def exactly(count)
|
77
|
+
Exactly.new(@sampler, count)
|
78
|
+
end
|
36
79
|
end
|
37
80
|
end
|
38
81
|
end
|
@@ -26,15 +26,19 @@ module Sus
|
|
26
26
|
# @parameter parent [Class] The parent test context class.
|
27
27
|
# @parameter description [String] The description of the measure.
|
28
28
|
# @parameter unique [Boolean] Whether the measure should have a unique identity.
|
29
|
+
# @parameter **options [Hash] Options to pass to the Sampler constructor.
|
29
30
|
# @parameter block [Proc] The block to execute for the measure.
|
30
31
|
# @returns [Class] The new measure class.
|
31
|
-
def self.build(parent, description, unique: true, &block)
|
32
|
+
def self.build(parent, description, unique: true, **options, &block)
|
32
33
|
base = Class.new(parent)
|
33
34
|
base.extend(self)
|
34
35
|
base.description = description
|
35
36
|
base.identity = Identity.nested(parent.identity, base.description, unique: unique)
|
36
37
|
base.set_temporary_name("#{self}[#{description}]")
|
37
38
|
|
39
|
+
# Store sampler options for later use
|
40
|
+
base.define_singleton_method(:sampler_options) {options}
|
41
|
+
|
38
42
|
if block_given?
|
39
43
|
base.define_method(:run, &block)
|
40
44
|
end
|
@@ -67,7 +71,8 @@ module Sus
|
|
67
71
|
assertions.nested(self, identity: self.identity, isolated: true, measure: true) do |assertions|
|
68
72
|
instance = self.new(assertions)
|
69
73
|
|
70
|
-
|
74
|
+
# Create sampler with options
|
75
|
+
samples = Sampler.new(**self.sampler_options)
|
71
76
|
repeats = Repeats.new(samples)
|
72
77
|
|
73
78
|
instance.around do
|
data/readme.md
CHANGED
@@ -18,6 +18,10 @@ Please see the [project documentation](https://suspecting.github.io/sus-fixtures
|
|
18
18
|
|
19
19
|
Please see the [project releases](https://suspecting.github.io/sus-fixtures-benchmark/releases/index) for all releases.
|
20
20
|
|
21
|
+
### v0.2.0
|
22
|
+
|
23
|
+
- Added `exactly(count)` method to `Sus::Fixtures::Benchmark::Repeats` which returns an `Exactly` instance for fixed-count benchmarking.
|
24
|
+
|
21
25
|
### v0.1.0
|
22
26
|
|
23
27
|
- Added `Sus::Fixtures::Benchmark::Repeats` which is not an integer, but an instance that allows the block to be executed multiple times until the benchmark converges.
|
data/releases.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v0.2.0
|
4
|
+
|
5
|
+
- Added `exactly(count)` method to `Sus::Fixtures::Benchmark::Repeats` which returns an `Exactly` instance for fixed-count benchmarking.
|
6
|
+
|
3
7
|
## v0.1.0
|
4
8
|
|
5
9
|
- Added `Sus::Fixtures::Benchmark::Repeats` which is not an integer, but an instance that allows the block to be executed multiple times until the benchmark converges.
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
-
|
2
|
-
�
|
3
|
-
|
1
|
+
AH�pb�D��J�%wg��(�^�ܜ�S>u����M���9�䋈�� ��O�;�r�wcgf9������vԨ��݅R�0�IJ���8_A�5.���g�0�$�ꈍ�̠�:|��T7�l�YQީ��o����a���9�53IWJ�X��8�T�wP���x|x0�Z.vp�3��c����i7�Ք��rrc�\�̶N��
|
2
|
+
oɷ5�k@I
|
3
|
+
��
|
4
|
+
7���M�ߨ��r����0�!0]:Iv��`W�zq�
|
5
|
+
|