-
Notifications
You must be signed in to change notification settings - Fork 10
/
benchmark_test.go
127 lines (108 loc) · 2.89 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"fmt"
"image"
"testing"
"time"
)
type BenchmarkConfig struct {
MaxIterValues []int
ImgSizeValues []int
loc Location
}
func getBenchmarkConfig() BenchmarkConfig {
imgConf = ImageConfig{
Width: -1,
Height: -1,
Samples: 5,
MaxIter: -1,
Offset: 0.0,
Mixing: true,
InsideBlack: true,
Grayscale: false,
RndGlobal: uint64(time.Now().UnixNano()),
}
return BenchmarkConfig{
MaxIterValues: []int{10, 100, 1000, 10000},
ImgSizeValues: []int{100, 1000},
loc: Location{
XCenter: -0.5,
YCenter: 0,
Zoom: 1,
},
}
}
func BenchmarkRenderImage(b *testing.B) {
benchmarkConfig := getBenchmarkConfig()
for _, size := range benchmarkConfig.ImgSizeValues {
imgConf.Height = size
imgConf.Width = size
for _, maxIter := range benchmarkConfig.MaxIterValues {
imgConf.MaxIter = maxIter
testId := fmt.Sprintf("Size_%d_MaxIter_%d", size, maxIter)
b.Run(testId, func(subB *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, imgConf.Width, imgConf.Height))
subB.ResetTimer()
for i := 0; i < subB.N; i++ {
renderImage(img, benchmarkConfig.loc)
}
})
}
}
}
func BenchmarkRenderRow(b *testing.B) {
benchmarkConfig := getBenchmarkConfig()
for _, size := range benchmarkConfig.ImgSizeValues {
imgConf.Height = size
imgConf.Width = size
for _, maxIter := range benchmarkConfig.MaxIterValues {
imgConf.MaxIter = maxIter
testId := fmt.Sprintf("Size_%d_MaxIter_%d", size, maxIter)
b.Run(testId, func(subB *testing.B) {
img := image.NewRGBA(image.Rect(0, 0, imgConf.Width, imgConf.Height))
subB.ResetTimer()
rndLocal := RandUint64(&imgConf.RndGlobal)
for i := 0; i < subB.N; i++ {
renderRow(benchmarkConfig.loc, imgConf.Height/2, img, &rndLocal)
}
})
}
}
}
func BenchmarkGetColorForPixel(b *testing.B) {
benchmarkConfig := getBenchmarkConfig()
imgConf.Height = 1000
imgConf.Width = 1000
for _, maxIter := range benchmarkConfig.MaxIterValues {
imgConf.MaxIter = maxIter
testId := fmt.Sprintf("MaxIter_%d", maxIter)
b.Run(testId, func(subB *testing.B) {
subB.ResetTimer()
for i := 0; i < subB.N; i++ {
getColorForPixel(benchmarkConfig.loc, imgConf.Height/2, imgConf.Width/2, &imgConf.RndGlobal)
}
})
}
}
func BenchmarkGetColorFromMandelbrotUnlimited(b *testing.B) {
magnitude := 2.0
iterations := 100
b.ResetTimer()
for i := 0; i < b.N; i++ {
getColorFromMandelbrot(true, magnitude, iterations)
}
}
func BenchmarkRunMandelbrot(b *testing.B) {
benchmarkConfig := getBenchmarkConfig()
c := complex(-0.5, 0) // (-0.5, 0) is part of the mandelbrot set, i.e. zn is bounded for all zn
for _, maxIter := range benchmarkConfig.MaxIterValues {
testId := fmt.Sprintf("MaxIter_%d", maxIter)
b.Run(testId, func(subB *testing.B) {
imgConf.MaxIter = maxIter
subB.ResetTimer()
for i := 0; i < subB.N; i++ {
runMandelbrot(c)
}
})
}
}