-
Notifications
You must be signed in to change notification settings - Fork 35
/
h1d_bench_test.go
118 lines (102 loc) · 2.02 KB
/
h1d_bench_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
// Copyright ©2020 The go-hep Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package hbook
import (
"math/rand"
"sync"
"testing"
)
var (
seed = rand.Uint32()
g_seed = &seed
)
// rnd is a simple minded non-thread-safe version of math/rand.Float64
func rnd() float64 {
ss := *g_seed
ss += ss
ss ^= 1
if int32(ss) < 0 {
ss ^= 0x88888eef
}
*g_seed = ss
return float64(*g_seed%95) / float64(95)
}
func BenchmarkH1DSTFillConst(b *testing.B) {
b.StopTimer()
h1 := NewH1D(100, 0., 100.)
b.StartTimer()
for i := 0; i < b.N; i++ {
h1.Fill(10., 1.)
}
}
func BenchmarkH1DFillFlat(b *testing.B) {
b.StopTimer()
h1 := NewH1D(100, 0., 100.)
b.StartTimer()
for i := 0; i < b.N; i++ {
h1.Fill(rnd()*100., 1.)
}
}
func BenchmarkH1DFillFlatGo(b *testing.B) {
b.StopTimer()
h1 := NewH1D(100, 0., 100.)
wg := new(sync.WaitGroup)
//wg.Add(b.N)
b.StartTimer()
// throttle...
q := make(chan struct{}, 1000)
for i := 0; i < b.N; i++ {
q <- struct{}{}
wg.Add(1)
go func() {
h1.Fill(rnd()*100., 1.)
<-q
wg.Done()
}()
}
wg.Wait()
}
func st_process_evts(n int, hists []*H1D, process func(hists []*H1D)) {
var wg sync.WaitGroup
for i := 0; i < n; i++ {
wg.Add(1)
go func() {
process(hists)
wg.Done()
}()
}
wg.Wait()
}
func st_process_evts_const(hists []*H1D) {
for _, h := range hists {
h.Fill(10., 1.)
}
}
func BenchmarkNH1DFillConst(b *testing.B) {
b.StopTimer()
hists := make([]*H1D, 100)
for i := 0; i < 100; i++ {
hists[i] = NewH1D(100, 0., 100.)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
st_process_evts(100, hists, st_process_evts_const)
}
}
func st_process_evts_flat(hists []*H1D) {
for _, h := range hists {
h.Fill(rnd()*100., 1.)
}
}
func BenchmarkNH1DFillFlat(b *testing.B) {
b.StopTimer()
hists := make([]*H1D, 100)
for i := 0; i < 100; i++ {
hists[i] = NewH1D(100, 0., 100.)
}
b.StartTimer()
for i := 0; i < b.N; i++ {
st_process_evts(100, hists, st_process_evts_flat)
}
}