add benchmarks

This commit is contained in:
Jonathan J Lawlor
2014-11-15 14:16:30 -05:00
parent 6a93054869
commit 90ad2f48c7

View File

@@ -5,6 +5,7 @@
package stat
import (
"math/rand"
"testing"
"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)
}*/