Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sample_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"time"
)

var ExportedF64 float64 // Assign to this to prevent dead code elimination

// Benchmark{Compute,Copy}{1000,1000000} demonstrate that, even for relatively
// expensive computations like Variance, the cost of copying the Sample, as
// approximated by a make and copy, is much greater than the cost of the
Expand All @@ -17,19 +19,23 @@ func BenchmarkCompute1000(b *testing.B) {
s[i] = int64(i)
}
b.ResetTimer()
var a float64
for i := 0; i < b.N; i++ {
SampleVariance(s)
a += SampleVariance(s)
}
ExportedF64 = a
}
func BenchmarkCompute1000000(b *testing.B) {
s := make([]int64, 1000000)
for i := 0; i < len(s); i++ {
s[i] = int64(i)
}
b.ResetTimer()
var a float64
for i := 0; i < b.N; i++ {
SampleVariance(s)
a += SampleVariance(s)
}
ExportedF64 = a
}
func BenchmarkCopy1000(b *testing.B) {
s := make([]int64, 1000)
Expand Down