Skip to content

feat: add population and sample standard deviation calculations - #15

Merged
kazeburo merged 1 commit into
mainfrom
feat/stddev
Oct 12, 2026
Merged

kazeburo merged 1 commit into
mainfrom
feat/stddev

Conversation

@kazeburo

@kazeburo kazeburo commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

PR Type

Enhancement, Tests, Documentation


Description

  • Add population and sample standard deviation methods.

  • Improve numerical stability for extreme values.

  • Test edge cases and document usage.


Diagram Walkthrough

flowchart LR
  view["Sorted view"]
  methods["PopulationStdDev and SampleStdDev"]
  calculation["Centered, scaled calculation"]
  result["Standard deviation or error"]
  view --> methods
  methods --> calculation
  calculation --> result
Loading

File Walkthrough

Relevant files
Enhancement
sorted.go
Add numerically stable standard deviation methods               

sorted.go

  • Add population and sample standard deviation methods.
  • Use centered, scaled calculations with compensated summation.
  • Handle empty inputs, insufficient samples, and infinities.
+56/-0   
Tests
sorted_test.go
Cover standard deviation results and edge cases                   

sorted_test.go

  • Test standard deviation across varied magnitudes and special values.
  • Verify small-input errors and frozen sorted views.
+91/-0   
Documentation
README.md
Document standard deviation APIs and behavior                       

README.md

  • Document both methods, formulas, usage, and error behavior.
  • Update English and Japanese feature descriptions.
+38/-2   

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

Benchmark Comparison

Base: main
PR: feat/stddev

BenchmarkSampdoAll results
goos: linux
goarch: amd64
pkg: github.com/monitoring-forge/sampdo
cpu: AMD EPYC 7763 64-Core Processor                
                                        │ base-bench.txt │            pr-bench.txt            │
                                        │     sec/op     │   sec/op     vs base               │
SampdoAll/sampdo/100000/duplicates-4         1.099m ± 7%   1.090m ± 2%       ~ (p=0.315 n=10)
SampdoAll/sampdo/100000/random-4             2.171m ± 2%   2.199m ± 1%       ~ (p=0.315 n=10)
SampdoAll/sampdo/100000/wide-4               2.246m ± 0%   2.242m ± 1%       ~ (p=0.436 n=10)
SampdoAll/sampdo/100000/sorted-4             165.0µ ± 3%   165.3µ ± 3%       ~ (p=0.353 n=10)
SampdoAll/sampdo/100000/response_time-4      1.720m ± 2%   1.714m ± 2%       ~ (p=0.971 n=10)
geomean                                      1.088m        1.088m       +0.01%

                                        │ base-bench.txt │             pr-bench.txt              │
                                        │      B/op      │     B/op      vs base                 │
SampdoAll/sampdo/100000/duplicates-4        1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.726 n=10)
SampdoAll/sampdo/100000/random-4            1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.588 n=10)
SampdoAll/sampdo/100000/wide-4              1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.924 n=10)
SampdoAll/sampdo/100000/sorted-4            785.1Ki ± 0%   785.1Ki ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/response_time-4     1.532Mi ± 0%   1.532Mi ± 0%       ~ (p=0.895 n=10)
geomean                                     1.334Mi        1.334Mi       +0.00%
¹ all samples are equal

                                        │ base-bench.txt │            pr-bench.txt             │
                                        │   allocs/op    │ allocs/op   vs base                 │
SampdoAll/sampdo/100000/duplicates-4          5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/random-4              5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/wide-4                5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/sorted-4              4.000 ± 0%   4.000 ± 0%       ~ (p=1.000 n=10) ¹
SampdoAll/sampdo/100000/response_time-4       5.000 ± 0%   5.000 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                       4.782        4.782       +0.00%
¹ all samples are equal

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@kazeburo
kazeburo merged commit bbeb2d4 into main Oct 12, 2026
4 checks passed
@kazeburo
kazeburo deleted the feat/stddev branch October 12, 2026 08:12
@github-actions github-actions Bot mentioned this pull request Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant