github.com/gopherd/gonum@v0.0.4/lapack/testlapack/dlangb_bench.go (about) 1 // Copyright ©2021 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package testlapack 6 7 import ( 8 "fmt" 9 "testing" 10 11 "math/rand" 12 13 "github.com/gopherd/gonum/lapack" 14 ) 15 16 func DlangbBenchmark(b *testing.B, impl Dlangber) { 17 rnd := rand.New(rand.NewSource(1)) 18 for _, bm := range []struct { 19 n, k int 20 }{ 21 {n: 1000, k: 0}, 22 {n: 1000, k: 1}, 23 {n: 1000, k: 2}, 24 {n: 1000, k: 5}, 25 {n: 1000, k: 8}, 26 {n: 1000, k: 10}, 27 {n: 1000, k: 20}, 28 {n: 1000, k: 30}, 29 {n: 10000, k: 0}, 30 {n: 10000, k: 1}, 31 {n: 10000, k: 2}, 32 {n: 10000, k: 5}, 33 {n: 10000, k: 8}, 34 {n: 10000, k: 10}, 35 {n: 10000, k: 30}, 36 {n: 10000, k: 60}, 37 {n: 10000, k: 100}, 38 } { 39 n := bm.n 40 k := bm.k 41 lda := 2*k + 1 42 aCopy := make([]float64, n*lda) 43 for i := range aCopy { 44 aCopy[i] = 1 - 2*rnd.Float64() 45 } 46 a := make([]float64, len(aCopy)) 47 48 for _, norm := range []lapack.MatrixNorm{lapack.MaxAbs, lapack.MaxRowSum, lapack.MaxColumnSum} { 49 name := fmt.Sprintf("%v_N=%v_K=%v", normToString(norm), n, k) 50 b.Run(name, func(b *testing.B) { 51 for i := 0; i < b.N; i++ { 52 result = impl.Dlangb(norm, n, n, k, k, a, lda) 53 } 54 }) 55 } 56 57 // Frobenius norm is benchmarked separately because its execution time 58 // depends on the element magnitude. 59 norm := lapack.Frobenius 60 for _, scale := range []string{"Small", "Medium", "Big"} { 61 name := fmt.Sprintf("%v_N=%v_K=%v_%v", normToString(norm), n, k, scale) 62 var scl float64 63 switch scale { 64 default: 65 scl = 1 66 case "Small": 67 scl = smlnum 68 case "Big": 69 scl = bignum 70 } 71 // Scale some elements so that the matrix contains a mix of small 72 // and medium, all medium, or big and medium values. 73 copy(a, aCopy) 74 for i := range a { 75 if i%2 == 0 { 76 a[i] *= scl 77 } 78 } 79 b.Run(name, func(b *testing.B) { 80 for i := 0; i < b.N; i++ { 81 result = impl.Dlangb(norm, n, n, k, k, a, lda) 82 } 83 }) 84 } 85 } 86 }