Skip to content

Commit

Permalink
TST: Add benchmark tests (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkleiven authored Sep 9, 2021
1 parent 0daf3e8 commit d49ad0c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions nonlin/newtonKrylov_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,51 @@ func TestBicStab(t *testing.T) {
}
}
}

func BenchmarkTestBicStab_3Unknowns(b *testing.B) {
for i := 0; i < b.N; i++ {
p := Problem{
F: func(out []float64, x []float64) {
out[0] = math.Cos(x[0]) - 9.0 + 3.0*x[0] + 8*math.Exp(x[1])
out[1] = math.Cos(x[1]) - 9.0 + 3.0*x[1] + 8*math.Exp(x[0])
out[2] = math.Cos(x[2]) - x[2] - 1.0
},
}

solver := NewtonKrylov{
Maxiter: 1000,
StepSize: 1e-3,
Tol: 1e-7,
Stencil: 6,
}
init := []float64{0.1, 0.35, 2.4}
solver.Solve(p, init)
}
}

func BenchmarkTestBicStab_100Unknowns(b *testing.B) {
n := 100
for i := 0; i < b.N; i++ {
p := Problem{
F: func(out []float64, x []float64) {
for i := range out {
out[i] = x[i]*x[i] - 0.01
}
},
}

solver := NewtonKrylov{
Maxiter: 1000,
StepSize: 1e-3,
Tol: 1e-7,
Stencil: 6,
}

init := make([]float64, n)
for i := range init {
init[i] = 5.0
}

solver.Solve(p, init)
}
}

0 comments on commit d49ad0c

Please sign in to comment.