SLIDE 5 Performance
go test -bench .
times all BenchmarkXXX functions
func Dot(A, B []float64) float64{ dot := 0.0 for i := range A{ dot += A[i] * B[i] } return dot } func BenchmarkDot(b *testing.B) { A, B := make([]float64, 1024), make([]float64, 1024) sum := 0.0 for i:=0; i<b.N; i++{ sum += Dot(A, B) } fmt.Fprintln(DevNull, sum) // use result }
Run
PASS BenchmarkDot 1000000 1997 ns/op Program exited.
Run Kill Close
Profiling
Go has built-in profiling
go tool pprof
- utputs your program's call graph with time spent per function
github.com/mumax/3/engine.(*_setter).Set 0 (0.0%)
github.com/mumax/3/engine.SetTorque 0 (0.0%)
113
github.com/mumax/3/engine.SetEffectiveField 0 (0.0%)
102
github.com/mumax/3/engine.SetDemagField 0 (0.0%)
81
github.com/mumax/3/engine.SetLLTorque 0 (0.0%)
108 102 81
github.com/mumax/3/engine.(*_adder).AddTo 0 (0.0%)
17
github.com/mumax/3/engine.demagConv 0 (0.0%)
24 28 github.com/mumax/3/mag.DemagKernel 20 (1.8%)
23
github.com/mumax/3/engine.AddAnisotropyField 0 (0.0%)
10
github.com/mumax/3/engine.AddExchangeField 0 (0.0%)
6 10 2