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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63078795b33d87a934f27e4b1a3499b67a5a1dbc3d4fb9c50cc83a3014dc9916
4
- data.tar.gz: c2c82e5e602dfd1f3a2e9f27609cbd518fc8822b70da8bb226a606bd9f6de06a
3
+ metadata.gz: 91585211a64e9c0976bfb3df369a629697cc777f7fdbf542a4465e20aa546f12
4
+ data.tar.gz: 2198dc293faa26db8c3e7d200f825debb60c317851185f020e95f743422e034c
5
5
  SHA512:
6
- metadata.gz: a7fb2ab5b00ab5061b5fee54bb1bdfe0587ec6e95f811eca1b49e914a3511c0f7da13dbabe861b30c797c476c65577d3eb4200243cd2557ce19083b25269ab0a
7
- data.tar.gz: 96a95d1c1e20585ff56e82035b0819f0c40cb967436ef32837bc389e67524b318e7e04b2ac863f55d172f8e108151e2850de2d169d4b36b10e796514ddb626a4
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 samples [Sampler] The sampler object to collect timing data.
16
- def initialize(samples)
17
- @samples = samples
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
- @samples.add(time.real)
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 @samples.converged?
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
@@ -41,7 +41,7 @@ module Sus
41
41
  # The real (wall clock) time in seconds.
42
42
  # @returns [Float]
43
43
  attr :real
44
-
44
+
45
45
  # Returns a string representation of the real time in seconds.
46
46
  # @returns [String]
47
47
  def to_s
@@ -6,7 +6,7 @@
6
6
  module Sus
7
7
  module Fixtures
8
8
  module Benchmark
9
- VERSION = "0.1.0"
9
+ VERSION = "0.2.0"
10
10
  end
11
11
  end
12
12
  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
- samples = Sampler.new
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sus-fixtures-benchmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
@@ -1,3 +1,5 @@
1
- /��kb@^�
2
- 6�~�Z����I'� O��%�c�dP@*�Q���{W�+L?����T��N�P�tZ,8jH��;�@��k��S���g���J����n�[��\z��,�m����-W�(J���&�6�x���;n�� �%�C��M+�R��9���Qp>E�!�<,-�L�^�l�z��
3
- 2�(gg o�DN$�-%@p#0,�O+)�M���I��
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�5۝3IWJ�X��8�T�w P���x|x0�Z.vp�3��c����i7�Ք��rrc�\�̶N��
2
+ oɷ5k@I
3
+ ��
4
+ 7���M�ߨ��r����0�!0]:Iv��`W�zq�
5
+