sus-fixtures-benchmark 0.2.0 → 0.2.1
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/context/getting-started.md +127 -0
- data/lib/sus/fixtures/benchmark/version.rb +1 -1
- data/readme.md +6 -2
- data/releases.md +4 -0
- data.tar.gz.sig +0 -0
- metadata +5 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de94d05fdae13b52e4e260d2f2fc5fc65792436d6756409fb332e77e4bc64b81
|
4
|
+
data.tar.gz: c0a75a615f5021dbd5ae2f26bb6d5a1eb4ac7c9d5ae22955bffe6573106d260b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0212ff21fd9e1dc27a2ee42d08bce8e1a2a713bdb204c869789f37a651fa828ff9047d4c2b4f4c85cf1322c822ce232fa2691da90a8d1808e1e7b94636eeb9e4
|
7
|
+
data.tar.gz: 72b37243db4d7c841924e17458dae86e8c028f1327f27711ece5603cb21f87831399498756fe2e1b4ad09be3119db714208c918c99d22a8742bb9efff1c47d0d
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
@@ -0,0 +1,127 @@
|
|
1
|
+
# Getting Started
|
2
|
+
|
3
|
+
This guide explains how to use the `sus-fixtures-benchmark` gem to measure and benchmark code performance within your Sus test suite.
|
4
|
+
|
5
|
+
## Quick Start
|
6
|
+
|
7
|
+
### Project Structure
|
8
|
+
|
9
|
+
We recommend organizing your benchmarks in a dedicated `benchmark/` directory:
|
10
|
+
|
11
|
+
```
|
12
|
+
your-project/
|
13
|
+
├── benchmark/
|
14
|
+
│ ├── database_performance.rb
|
15
|
+
│ ├── algorithm_comparison.rb
|
16
|
+
│ └── memory_usage.rb
|
17
|
+
├── test/
|
18
|
+
├── lib/
|
19
|
+
└── Gemfile
|
20
|
+
```
|
21
|
+
|
22
|
+
This keeps your benchmarks separate from your regular tests and makes them easy to find and run.
|
23
|
+
|
24
|
+
### Basic Measurement
|
25
|
+
|
26
|
+
The simplest way to measure code performance is using the `measure` method:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
# benchmark/array_performance.rb
|
30
|
+
require "sus/fixtures/benchmark"
|
31
|
+
|
32
|
+
describe "Array Performance" do
|
33
|
+
include Sus::Fixtures::Benchmark
|
34
|
+
|
35
|
+
let(:data) {(1..1000).to_a}
|
36
|
+
|
37
|
+
measure "array iteration" do |repeats|
|
38
|
+
repeats.times do
|
39
|
+
data.each{|i| i * 2}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
|
45
|
+
This will automatically run your code until statistical convergence is reached and report the results.
|
46
|
+
|
47
|
+
**Run with:** `sus --verbose benchmark/array_performance.rb`
|
48
|
+
|
49
|
+
### Understanding the Output
|
50
|
+
|
51
|
+
When you run your tests with `sus --verbose`, you'll see output like:
|
52
|
+
|
53
|
+
```
|
54
|
+
measure array iteration 34 samples, mean: 0.15ms, standard deviation: 0.02ms, standard error: 0.003ms
|
55
|
+
```
|
56
|
+
|
57
|
+
**Important:** You must run `sus --verbose` to see the benchmark output. Without the verbose flag, the benchmark results will not be displayed.
|
58
|
+
|
59
|
+
This tells you:
|
60
|
+
- **34 samples**: How many times the code was executed.
|
61
|
+
- **mean: 0.15ms**: Average execution time.
|
62
|
+
- **standard deviation: 0.02ms**: How much variation there was between runs.
|
63
|
+
- **standard error: 0.003ms**: How reliable the mean estimate is.
|
64
|
+
|
65
|
+
## Measurement Modes
|
66
|
+
|
67
|
+
### Automatic Convergence (Default)
|
68
|
+
|
69
|
+
By default, the benchmark runs until it achieves statistical convergence:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
measure "database query" do |repeats|
|
73
|
+
repeats.times do
|
74
|
+
User.where(active: true).count
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
The system will automatically determine when it has enough samples to provide a reliable measurement based on:
|
80
|
+
- **Confidence level**: 95% by default
|
81
|
+
- **Margin of error**: 2% of the mean by default (0.02)
|
82
|
+
- **Minimum samples**: 8 by default
|
83
|
+
|
84
|
+
### Fixed Number of Iterations
|
85
|
+
|
86
|
+
If you need a specific number of iterations, use the `exactly` method:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
measure "quick test" do |repeats|
|
90
|
+
repeats.exactly(10).times do
|
91
|
+
# Your code here
|
92
|
+
end
|
93
|
+
end
|
94
|
+
```
|
95
|
+
|
96
|
+
This is useful for:
|
97
|
+
- Quick smoke tests.
|
98
|
+
- When you know the exact number of iterations needed.
|
99
|
+
- Debugging or development scenarios.
|
100
|
+
|
101
|
+
## Configuration Options
|
102
|
+
|
103
|
+
### Customizing the Sampler
|
104
|
+
|
105
|
+
You can customize the statistical parameters directly in the `measure` method:
|
106
|
+
|
107
|
+
```ruby
|
108
|
+
measure "high precision", minimum: 20, confidence: 0.98, margin_of_error: 0.01 do |repeats|
|
109
|
+
repeats.times do
|
110
|
+
# Your code here
|
111
|
+
end
|
112
|
+
end
|
113
|
+
```
|
114
|
+
|
115
|
+
### Parameter Reference
|
116
|
+
|
117
|
+
You should try to avoid deviating from the defaults.
|
118
|
+
|
119
|
+
- **`minimum`** (Integer): Minimum samples before convergence (default: 8).
|
120
|
+
- **Lower `minimum`**: Quick development feedback (e.g., `minimum: 3`)
|
121
|
+
- **Higher `minimum`**: High-variance operations (e.g., `minimum: 30`)
|
122
|
+
- **`confidence`** (Float): Confidence level 0.0-1.0 (default: 0.95). High confidence (above 0.98) may take an extremely long time to converge.
|
123
|
+
- **Lower `confidence`**: Faster results (e.g., `confidence: 0.90`)
|
124
|
+
- **Higher `confidence`**: Production guarantees (e.g., `confidence: 0.98`)
|
125
|
+
- **`margin_of_error`** (Float): Acceptable error as a fraction of the mean (default: 0.02 = 2%).
|
126
|
+
- **Lower `margin_of_error`**: High precision (e.g., `margin_of_error: 0.01`)
|
127
|
+
- **Higher `margin_of_error`**: Rough estimates (e.g., `margin_of_error: 0.05`)
|
data/readme.md
CHANGED
@@ -12,11 +12,15 @@ bundle add sus-fixtures-benchmark
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
-
Please see the [project documentation](https://
|
15
|
+
Please see the [project documentation](https://socketry.github.io/sus-fixtures-benchmark/) for more details.
|
16
16
|
|
17
17
|
## Releases
|
18
18
|
|
19
|
-
Please see the [project releases](https://
|
19
|
+
Please see the [project releases](https://socketry.github.io/sus-fixtures-benchmark/releases/index) for all releases.
|
20
|
+
|
21
|
+
### v0.2.1
|
22
|
+
|
23
|
+
- Fix links and add context.
|
20
24
|
|
21
25
|
### v0.2.0
|
22
26
|
|
data/releases.md
CHANGED
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -57,6 +57,7 @@ extensions: []
|
|
57
57
|
extra_rdoc_files: []
|
58
58
|
files:
|
59
59
|
- agent.md
|
60
|
+
- context/getting-started.md
|
60
61
|
- lib/sus/fixtures/benchmark.rb
|
61
62
|
- lib/sus/fixtures/benchmark/repeats.rb
|
62
63
|
- lib/sus/fixtures/benchmark/sampler.rb
|
@@ -65,13 +66,13 @@ files:
|
|
65
66
|
- license.md
|
66
67
|
- readme.md
|
67
68
|
- releases.md
|
68
|
-
homepage: https://github.com/
|
69
|
+
homepage: https://github.com/socketry/sus-fixtures-benchmark
|
69
70
|
licenses:
|
70
71
|
- MIT
|
71
72
|
metadata:
|
72
|
-
documentation_uri: https://
|
73
|
+
documentation_uri: https://socketry.github.io/sus-fixtures-benchmark/
|
73
74
|
funding_uri: https://github.com/sponsors/ioquatix/
|
74
|
-
source_code_uri: https://github.com/
|
75
|
+
source_code_uri: https://github.com/socketry/sus-fixtures-benchmark.git
|
75
76
|
rdoc_options: []
|
76
77
|
require_paths:
|
77
78
|
- lib
|
metadata.gz.sig
CHANGED
Binary file
|