diff --git a/asm/f64/benchOthr_test.go b/asm/f64/bench_other_test.go similarity index 97% rename from asm/f64/benchOthr_test.go rename to asm/f64/bench_other_test.go index 4f82d1d6..847abeba 100644 --- a/asm/f64/benchOthr_test.go +++ b/asm/f64/bench_other_test.go @@ -6,19 +6,14 @@ package f64 import ( "math" - "runtime" "testing" ) func benchAbsSum(f func(x []float64) float64, sz int, t *testing.B) { dst := y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(dst) } - t.StopTimer() - runtime.GC() } var naiveAbsSum = func(x []float64) (sum float64) { @@ -53,12 +48,9 @@ func BenchmarkLAbsSum100000(t *testing.B) { benchAbsSum(naiveAbsSum, 100000, t) func BenchmarkLAbsSum500000(t *testing.B) { benchAbsSum(naiveAbsSum, 500000, t) } func benchAbsSumInc(t *testing.B, ln, inc int, f func(x []float64, n, incX int) float64) { - t.ResetTimer() for i := 0; i < t.N; i++ { f(x, ln, inc) } - t.StopTimer() - runtime.GC() } var naiveAbsSumInc = func(x []float64, n, incX int) (sum float64) { @@ -134,13 +126,9 @@ func BenchmarkLF64AbsSumIncN100000Inc10(b *testing.B) { benchAbsSumInc(b, 100000 func benchAdd(f func(dst, s []float64), sz int, t *testing.B) { dst, s := y[:sz], x[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(dst, s) } - t.StopTimer() - runtime.GC() } var naiveAdd = func(dst, s []float64) { @@ -175,13 +163,9 @@ func BenchmarkLAdd500000(t *testing.B) { benchAdd(naiveAdd, 500000, t) } func benchAddConst(f func(a float64, x []float64), sz int, t *testing.B) { a, x := 1., x[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, x) } - t.StopTimer() - runtime.GC() } var naiveAddConst = func(a float64, x []float64) { @@ -216,13 +200,9 @@ func BenchmarkLAddConst500000(t *testing.B) { benchAddConst(naiveAddConst, 50000 func benchCumSum(f func(a, b []float64) []float64, sz int, t *testing.B) { a, b := x[:sz], y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, b) } - t.StopTimer() - runtime.GC() } var naiveCumSum = func(dst, s []float64) []float64 { @@ -262,13 +242,9 @@ func BenchmarkLCumSum500000(t *testing.B) { benchCumSum(naiveCumSum, 500000, t) func benchCumProd(f func(a, b []float64) []float64, sz int, t *testing.B) { a, b := x[:sz], y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, b) } - t.StopTimer() - runtime.GC() } var naiveCumProd = func(dst, s []float64) []float64 { @@ -308,13 +284,9 @@ func BenchmarkLCumProd500000(t *testing.B) { benchCumProd(naiveCumProd, 500000, func benchDiv(f func(a, b []float64), sz int, t *testing.B) { a, b := x[:sz], y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, b) } - t.StopTimer() - runtime.GC() } var naiveDiv = func(a, b []float64) { @@ -349,13 +321,9 @@ func BenchmarkLDiv500000(t *testing.B) { benchDiv(naiveDiv, 500000, t) } func benchDivTo(f func(dst, a, b []float64) []float64, sz int, t *testing.B) { dst, a, b := z[:sz], x[:sz], y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(dst, a, b) } - t.StopTimer() - runtime.GC() } var naiveDivTo = func(dst, s, t []float64) []float64 { @@ -391,13 +359,9 @@ func BenchmarkLDivTo500000(t *testing.B) { benchDivTo(naiveDivTo, 500000, t) } func benchL1Norm(f func(a, b []float64) float64, sz int, t *testing.B) { a, b := x[:sz], y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, b) } - t.StopTimer() - runtime.GC() } var naiveL1Norm = func(s, t []float64) float64 { @@ -434,13 +398,9 @@ func BenchmarkLL1Norm500000(t *testing.B) { benchL1Norm(naiveL1Norm, 500000, t) func benchLinfNorm(f func(a, b []float64) float64, sz int, t *testing.B) { a, b := x[:sz], y[:sz] - - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, b) } - t.StopTimer() - runtime.GC() } var naiveLinfNorm = func(s, t []float64) float64 { diff --git a/asm/f64/bench_test.go b/asm/f64/bench_test.go index a737ddfa..20adc919 100644 --- a/asm/f64/bench_test.go +++ b/asm/f64/bench_test.go @@ -4,10 +4,7 @@ package f64 -import ( - "runtime" - "testing" -) +import "testing" var ( a = float64(2) @@ -26,12 +23,9 @@ func init() { func benchaxpyu(t *testing.B, n int, f func(a float64, x, y []float64)) { x, y := x[:n], y[:n] - t.ResetTimer() for i := 0; i < t.N; i++ { f(a, x, y) } - t.StopTimer() - runtime.GC() } func naiveaxpyu(a float64, x, y []float64) { @@ -67,12 +61,9 @@ func BenchmarkLF64AxpyUnitary50000(t *testing.B) { benchaxpyu(t, 50000, naiveaxp func benchaxpyut(t *testing.B, n int, f func(d []float64, a float64, x, y []float64)) { x, y, z := x[:n], y[:n], z[:n] - t.ResetTimer() for i := 0; i < t.N; i++ { f(z, a, x, y) } - t.StopTimer() - runtime.GC() } func naiveaxpyut(d []float64, a float64, x, y []float64) { @@ -112,12 +103,9 @@ func benchaxpyinc(t *testing.B, ln, t_inc int, f func(alpha float64, x, y []floa idx = (-ln + 1) * t_inc } - t.ResetTimer() for i := 0; i < t.N; i++ { f(1, x, y, n, inc, inc, uintptr(idx), uintptr(idx)) } - t.StopTimer() - runtime.GC() } func naiveaxpyinc(alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) { @@ -209,12 +197,9 @@ func benchaxpyincto(t *testing.B, ln, t_inc int, f func(dst []float64, incDst, i idx = (-ln + 1) * t_inc } - t.ResetTimer() for i := 0; i < t.N; i++ { f(z, inc, uintptr(idx), 1, x, y, n, inc, inc, uintptr(idx), uintptr(idx)) } - t.StopTimer() - runtime.GC() } func naiveaxpyincto(dst []float64, incDst, idst uintptr, alpha float64, x, y []float64, n, incX, incY, ix, iy uintptr) { diff --git a/asm/f64/stubs_test.go b/asm/f64/stubs_test.go index b330f4f9..f72e332d 100644 --- a/asm/f64/stubs_test.go +++ b/asm/f64/stubs_test.go @@ -24,7 +24,7 @@ func guardVector(v []float64, g float64, g_ln int) (guarded []float64) { return guarded } -func validGuard(v []float64, g float64, g_ln int) bool { +func isValidGuard(v []float64, g float64, g_ln int) bool { for i := 0; i < g_ln; i++ { if !same(v[i], g) || v[len(v)-1-i] != g { return false @@ -50,20 +50,20 @@ func guardIncVector(v []float64, g float64, inc, g_ln int) (guarded []float64) { return guarded } -func validIncGuard(t *testing.T, v []float64, g float64, inc, g_ln int) { +func checkValidIncGuard(t *testing.T, v []float64, g float64, inc, g_ln int) { s_ln := len(v) - 2*g_ln for i := range v { switch { case same(v[i], g): // Correct value case i < g_ln: - t.Error("Front guard violated at", i, v[:g_ln]) + t.Errorf("Front guard violated at %d %v", i, v[:g_ln]) case i > g_ln+s_ln: - t.Error("Back guard violated at", i-g_ln-s_ln, v[g_ln+s_ln:]) + t.Errorf("Back guard violated at %d %v", i-g_ln-s_ln, v[g_ln+s_ln:]) case (i-g_ln)%inc == 0 && (i-g_ln)/inc < len(v): // Ignore input values default: - t.Error("Internal guard violated at", i-g_ln, v[g_ln:g_ln+s_ln]) + t.Errorf("Internal guard violated at %d %v", i-g_ln, v[g_ln:g_ln+s_ln]) } } } @@ -112,11 +112,10 @@ func TestAbsSum(t *testing.T) { src := v.src[g_ln : len(v.src)-g_ln] ret := AbsSum(src) if !same(ret, v.ex) { - t.Error("Test", j, "AbsSum error Got:", ret, "Expected:", v.ex) - t.Error(src) + t.Errorf("Test %d AbsSum error Got: %f Expected: %f", j, ret, v.ex) } - if !validGuard(v.src, src_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.src[:g_ln], v.src[len(v.src)-g_ln:]) + if !isValidGuard(v.src, src_gd, g_ln) { + t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) } } } @@ -169,10 +168,9 @@ func TestAbsSumInc(t *testing.T) { src := v.src[g_ln : len(v.src)-g_ln] ret := AbsSumInc(src, ln, v.inc) if !same(ret, v.ex) { - t.Error("Test", j, "AbsSum error Got:", ret, "Expected:", v.ex) - t.Error(src) + t.Errorf("Test %d AbsSumInc error Got: %f Expected: %f", j, ret, v.ex) } - validIncGuard(t, v.src, src_gd, v.inc, g_ln) + checkValidIncGuard(t, v.src, src_gd, v.inc, g_ln) } } @@ -223,14 +221,14 @@ func TestAdd(t *testing.T) { Add(dst, src) for i := range v.expect { if !same(dst[i], v.expect[i]) { - t.Error("Test", j, "Add error at", i, "Got:", dst[i], "Expected:", v.expect[i]) + t.Errorf("Test %d Add error at %d Got: %v Expected: %v", j, i, dst[i], v.expect[i]) } } - if !validGuard(v.src, src_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.src[:g_ln], v.src[len(v.src)-g_ln:]) + if !isValidGuard(v.src, src_gd, g_ln) { + t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) } - if !validGuard(v.dst, dst_gd, g_ln) { - t.Error("Test", j, "Guard violated in y vector", v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) + if !isValidGuard(v.dst, dst_gd, g_ln) { + t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) } } } @@ -273,11 +271,11 @@ func TestAddConst(t *testing.T) { AddConst(v.alpha, src) for i := range v.expect { if !same(src[i], v.expect[i]) { - t.Error("Test", j, "AddConst error at", i, "Got:", src[i], "Expected:", v.expect[i]) + t.Errorf("Test %d AddConst error at %d Got: %v Expected: %v", j, i, src[i], v.expect[i]) } } - if !validGuard(v.src, src_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.src[:g_ln], v.src[len(v.src)-g_ln:]) + if !isValidGuard(v.src, src_gd, g_ln) { + t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) } } } @@ -339,18 +337,17 @@ func TestCumSum(t *testing.T) { ret := CumSum(dst, src) for i := range v.expect { if !same(ret[i], v.expect[i]) { - t.Error("Test", j, "CumSum error at", i, "Got:", ret[i], "Expected:", v.expect[i]) - t.Error(ret, v.expect) + t.Errorf("Test %d CumSum error at %d Got: %v Expected: %v", j, i, ret[i], v.expect[i]) } if !same(ret[i], dst[i]) { - t.Error("Test", j, "CumSum ret/dst mismatch", i, "Ret:", ret[i], "Dst:", dst[i]) + t.Errorf("Test %d CumSum ret/dst mismatch %d Ret: %v Dst: %v", j, i, ret[i], dst[i]) } } - if !validGuard(v.src, src_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.src[:g_ln], v.src[len(v.src)-g_ln:]) + if !isValidGuard(v.src, src_gd, g_ln) { + t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) } - if !validGuard(v.dst, dst_gd, g_ln) { - t.Error("Test", j, "Guard violated in y vector", v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) + if !isValidGuard(v.dst, dst_gd, g_ln) { + t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) } } } @@ -412,17 +409,17 @@ func TestCumProd(t *testing.T) { ret := CumProd(dst, src) for i := range v.expect { if !same(ret[i], v.expect[i]) { - t.Error("Test", j, "CumProd error at", i, "Got:", ret[i], "Expected:", v.expect[i]) + t.Errorf("Test %d CumProd error at %d Got: %v Expected: %v", j, i, ret[i], v.expect[i]) } if !same(ret[i], dst[i]) { - t.Error("Test", j, "CumProd ret/dst mismatch", i, "Ret:", ret[i], "Dst:", dst[i]) + t.Errorf("Test %d CumProd ret/dst mismatch %d Ret: %v Dst: %v", j, i, ret[i], dst[i]) } } - if !validGuard(v.src, src_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.src[:g_ln], v.src[len(v.src)-g_ln:]) + if !isValidGuard(v.src, src_gd, g_ln) { + t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) } - if !validGuard(v.dst, dst_gd, g_ln) { - t.Error("Test", j, "Guard violated in y vector", v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) + if !isValidGuard(v.dst, dst_gd, g_ln) { + t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) } } } @@ -479,14 +476,14 @@ func TestDiv(t *testing.T) { Div(dst, src) for i := range v.expect { if !same(dst[i], v.expect[i]) { - t.Error("Test", j, "Div error at", i, "Got:", dst[i], "Expected:", v.expect[i]) + t.Errorf("Test %d Div error at %d Got: %v Expected: %v", j, i, dst[i], v.expect[i]) } } - if !validGuard(v.src, src_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.src[:g_ln], v.src[len(v.src)-g_ln:]) + if !isValidGuard(v.src, src_gd, g_ln) { + t.Errorf("Test %d Guard violated in src vector %v %v", j, v.src[:g_ln], v.src[len(v.src)-g_ln:]) } - if !validGuard(v.dst, dst_gd, g_ln) { - t.Error("Test", j, "Guard violated in y vector", v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) + if !isValidGuard(v.dst, dst_gd, g_ln) { + t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) } } } @@ -547,20 +544,20 @@ func TestDivTo(t *testing.T) { ret := DivTo(dst, x, y) for i := range v.expect { if !same(ret[i], v.expect[i]) { - t.Error("Test", j, "DivTo error at", i, "Got:", x[i], "Expected:", v.expect[i]) + t.Errorf("Test %d DivTo error at %d Got: %v Expected: %v", j, i, ret[i], v.expect[i]) } if !same(ret[i], dst[i]) { - t.Error("Test", j, "DivTo ret/dst mismatch", i, "Ret:", ret[i], "X:", dst[i]) + t.Errorf("Test %d DivTo ret/dst mismatch %d Ret: %v Dst: %v", j, i, ret[i], dst[i]) } } - if !validGuard(v.y, y_gd, g_ln) { - t.Error("Test", j, "Guard violated in x vector", v.y[:g_ln], v.y[len(v.y)-g_ln:]) + if !isValidGuard(v.y, y_gd, g_ln) { + t.Errorf("Test %d Guard violated in y vector %v %v", j, v.y[:g_ln], v.y[len(v.y)-g_ln:]) } - if !validGuard(v.x, x_gd, g_ln) { - t.Error("Test", j, "Guard violated in y vector", v.x[:g_ln], v.x[len(v.x)-g_ln:]) + if !isValidGuard(v.x, x_gd, g_ln) { + t.Errorf("Test %d Guard violated in x vector %v %v", j, v.x[:g_ln], v.x[len(v.x)-g_ln:]) } - if !validGuard(v.dst, dst_gd, g_ln) { - t.Error("Test", j, "Guard violated in dst vector", v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) + if !isValidGuard(v.dst, dst_gd, g_ln) { + t.Errorf("Test %d Guard violated in dst vector %v %v", j, v.dst[:g_ln], v.dst[len(v.dst)-g_ln:]) } } } @@ -617,13 +614,13 @@ func TestL1Norm(t *testing.T) { s_lc, t_lc := v.s[g_ln:len(v.s)-g_ln], v.t[g_ln:len(v.t)-g_ln] ret := L1Norm(s_lc, t_lc) if !same(ret, v.expect) { - t.Error("Test", j, "L1Norm error. Got:", ret, "Expected:", v.expect) + t.Errorf("Test %d L1Norm error Got: %f Expected: %f", j, ret, v.expect) } - if !validGuard(v.s, s_gd, g_ln) { - t.Error("Test", j, "Guard violated in s vector", v.s[:g_ln], v.s[len(v.s)-g_ln:]) + if !isValidGuard(v.s, s_gd, g_ln) { + t.Errorf("Test %d Guard violated in s vector %v %v", j, v.s[:g_ln], v.s[len(v.s)-g_ln:]) } - if !validGuard(v.t, t_gd, g_ln) { - t.Error("Test", j, "Guard violated in t vector", v.t[:g_ln], v.t[len(v.t)-g_ln:]) + if !isValidGuard(v.t, t_gd, g_ln) { + t.Errorf("Test %d Guard violated in t vector %v %v", j, v.t[:g_ln], v.t[len(v.t)-g_ln:]) } } } @@ -680,13 +677,13 @@ func TestLinfNorm(t *testing.T) { s_lc, t_lc := v.s[g_ln:len(v.s)-g_ln], v.t[g_ln:len(v.t)-g_ln] ret := LinfNorm(s_lc, t_lc) if !same(ret, v.expect) { - t.Error("Test", j, "LinfNorm error. Got:", ret, "Expected:", v.expect) + t.Errorf("Test %d LinfNorm error Got: %f Expected: %f", j, ret, v.expect) } - if !validGuard(v.s, s_gd, g_ln) { - t.Error("Test", j, "Guard violated in s vector", v.s[:g_ln], v.s[len(v.s)-g_ln:]) + if !isValidGuard(v.s, s_gd, g_ln) { + t.Errorf("Test %d Guard violated in s vector %v %v", j, v.s[:g_ln], v.s[len(v.s)-g_ln:]) } - if !validGuard(v.t, t_gd, g_ln) { - t.Error("Test", j, "Guard violated in t vector", v.t[:g_ln], v.t[len(v.t)-g_ln:]) + if !isValidGuard(v.t, t_gd, g_ln) { + t.Errorf("Test %d Guard violated in t vector %v %v", j, v.t[:g_ln], v.t[len(v.t)-g_ln:]) } } }