mirror of
https://github.com/gonum/gonum.git
synced 2025-10-27 09:11:08 +08:00
add benchmarks
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
package stat
|
package stat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gonum/blas/cblas"
|
"github.com/gonum/blas/cblas"
|
||||||
@@ -50,3 +51,98 @@ func TestCovarianceMatrix(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// benchmarks
|
||||||
|
|
||||||
|
func randMat(r, c int) mat64.Matrix {
|
||||||
|
x := make([]float64, r*c)
|
||||||
|
for i := range x {
|
||||||
|
x[i] = rand.Float64()
|
||||||
|
}
|
||||||
|
return mat64.NewDense(r, c, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func benchmarkCovarianceMatrix(b *testing.B, m mat64.Matrix) {
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
CovarianceMatrix(m)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkCovarianceMatrixSmallxSmall(b *testing.B) {
|
||||||
|
// 10 * 10 elements
|
||||||
|
x := randMat(SMALL, SMALL)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixSmallxMedium(b *testing.B) {
|
||||||
|
// 10 * 1000 elements
|
||||||
|
x := randMat(SMALL, MEDIUM)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*func BenchmarkCovarianceMatrixSmallxLarge(b *testing.B) {
|
||||||
|
x := randMat(SMALL, LARGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixSmallxHuge(b *testing.B) {
|
||||||
|
x := randMat(SMALL, HUGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
func BenchmarkCovarianceMatrixMediumxSmall(b *testing.B) {
|
||||||
|
// 1000 * 10 elements
|
||||||
|
x := randMat(MEDIUM, SMALL)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixMediumxMedium(b *testing.B) {
|
||||||
|
// 1000 * 1000 elements
|
||||||
|
x := randMat(MEDIUM, MEDIUM)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*func BenchmarkCovarianceMatrixMediumxLarge(b *testing.B) {
|
||||||
|
x := randMat(MEDIUM, LARGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixMediumxHuge(b *testing.B) {
|
||||||
|
x := randMat(MEDIUM, HUGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
func BenchmarkCovarianceMatrixLargexSmall(b *testing.B) {
|
||||||
|
// 1e5 * 10 elements
|
||||||
|
x := randMat(LARGE, SMALL)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*func BenchmarkCovarianceMatrixLargexMedium(b *testing.B) {
|
||||||
|
x := randMat(LARGE, MEDIUM)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixLargexLarge(b *testing.B) {
|
||||||
|
x := randMat(LARGE, LARGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixLargexHuge(b *testing.B) {
|
||||||
|
x := randMat(LARGE, HUGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}*/
|
||||||
|
|
||||||
|
func BenchmarkCovarianceMatrixHugexSmall(b *testing.B) {
|
||||||
|
// 1e7 * 10 elements
|
||||||
|
x := randMat(HUGE, SMALL)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
/*func BenchmarkCovarianceMatrixHugexMedium(b *testing.B) {
|
||||||
|
x := randMat(HUGE, MEDIUM)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixHugexLarge(b *testing.B) {
|
||||||
|
x := randMat(HUGE, LARGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}
|
||||||
|
func BenchmarkCovarianceMatrixHugexHuge(b *testing.B) {
|
||||||
|
x := randMat(HUGE, HUGE)
|
||||||
|
benchmarkCovarianceMatrix(b, x)
|
||||||
|
}*/
|
||||||
|
|||||||
Reference in New Issue
Block a user