-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark_test.go
110 lines (87 loc) · 2.03 KB
/
benchmark_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package vinamax2
// Benchmarks
import (
"testing"
)
// demag, 5 levels, 4096 particles, 0th order
func BenchmarkFMM5Levels0th(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
initBenchWorld(5)
FMMOrder = 0
b.StartTimer()
for i := 0; i < b.N; i++ {
CalcDemag()
}
}
func BenchmarkFMM5LevelsParallel(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
initBenchWorld(5)
CalcDemagParallel() // spin-up workers once
b.StartTimer()
for i := 0; i < b.N; i++ {
CalcDemagParallel()
}
}
// demag, 5 levels, 4096 particles, 1st order
func BenchmarkFMM5Levels1st(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
initBenchWorld(5)
FMMOrder = 1
b.StartTimer()
for i := 0; i < b.N; i++ {
CalcDemag()
}
}
func BenchmarkDipoleField(b *testing.B) {
m := Vector{1, 2, 3}
r := Vector{3, 4, 5}
for i := 0; i < b.N; i++ {
DipoleField(m, r)
}
}
// benchmark AddPartnerFields, the most time-consuming FMM stage, 0th-order
func BenchmarkAddPartnerFields0th(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
hotcell := initBenchWorld(5)
FMMOrder = 0
b.StartTimer()
for i := 0; i < b.N; i++ {
hotcell.addPartnerFields0()
}
}
// benchmark AddPartnerFields, the most time-consuming FMM stage, 1st order
func BenchmarkAddPartnerFields1st(b *testing.B) {
b.StopTimer()
b.ReportAllocs()
hotcell := initBenchWorld(5)
FMMOrder = 1
b.StartTimer()
for i := 0; i < b.N; i++ {
hotcell.addPartnerFields1()
}
}
func BenchmarkInitFMM(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
initBenchWorld(5)
}
}
// init standard world for benchmarking: with NLEVEL levels,
// one particle at each base cell center.
func initBenchWorld(NLEVEL int) *Cell {
worldSize := Vector{1, 1, 1}
InitFMM(worldSize, NLEVEL)
// place particles with m=0 , as field probes
baseLevel := Level[NLEVEL-1]
for _, c := range baseLevel {
AddParticle(&Particle{M: Vector{0, 0, 0}, center: c.center})
}
// place one magneticed particle as source
hotcell := baseLevel[30]
AddParticle(&Particle{M: Vector{1, 2, 3}, center: hotcell.center})
return hotcell
}