Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sync: move lock linearity test and treat it like a performance test
This change moves test/locklinear.go into the sync package tests, and adds a bit of infrastructure since there are other linearity-checking tests that could benefit from it too. This infrastructure is also different than what test/locklinear.go does: instead of trying really hard to get at least one success, we instead treat this like a performance test and look for a significant difference via a t-test. This makes the methodology behind the tests more rigorous, and should reduce flakiness as transient noise should produce an insignificant result. A follow-up CL does more to make these tests even more robust. For #32986. Change-Id: I408c5f643962b70ea708930edb4ac9df1c6123ce Reviewed-on: https://go-review.googlesource.com/c/go/+/411396 Reviewed-by: Michael Pratt <mpratt@google.com>
- Loading branch information
Showing
4 changed files
with
193 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2022 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package testmath | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type BenchmarkResults []testing.BenchmarkResult | ||
|
||
func (b BenchmarkResults) Weight() float64 { | ||
var weight int | ||
for _, r := range b { | ||
weight += r.N | ||
} | ||
return float64(weight) | ||
} | ||
|
||
func (b BenchmarkResults) Mean() float64 { | ||
var dur time.Duration | ||
for _, r := range b { | ||
dur += r.T * time.Duration(r.N) | ||
} | ||
return float64(dur) / b.Weight() | ||
} | ||
|
||
func (b BenchmarkResults) Variance() float64 { | ||
var num float64 | ||
mean := b.Mean() | ||
for _, r := range b { | ||
num += math.Pow(float64(r.T)-mean, 2) * float64(r.N) | ||
} | ||
return float64(num) / b.Weight() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.