-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsum_test.go
More file actions
224 lines (205 loc) · 7.89 KB
/
sum_test.go
File metadata and controls
224 lines (205 loc) · 7.89 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package promsketch
import (
"bufio"
"fmt"
"os"
"runtime"
"sync"
"sync/atomic"
"testing"
"time"
)
func funcEfficientSum(epsilon float64, item_window_size int64, time_window_size int64, GroundTruth map[string]([]AnswerSum2), w *bufio.Writer) {
fmt.Fprintf(w, "=================>Estimating with ExpoHistogram Count===================>\n")
w.Flush()
t2 := int64(time_window_size)
ehs := make(map[string](*EfficientSum))
for _, c := range cases {
ehs[c.key] = NewEfficientSum(item_window_size, time_window_size, epsilon, 5) // value_scale)
}
EHAnswer := make(map[string]([]AnswerSum2))
for _, c := range cases {
EHAnswer[c.key] = make([]AnswerSum2, 0)
}
for t := int64(0); t < time_window_size*2; t++ {
for _, c := range cases {
ehs[c.key].Insert(c.vec[t].T, c.vec[t].F)
if t >= t2 {
start := time.Now()
ans_sum := ehs[c.key].Query(t-t2, t, false)
elapsed := time.Since(start)
EHAnswer[c.key] = append(EHAnswer[c.key], AnswerSum2{sum: ans_sum, time: float64(elapsed.Microseconds()), memory: ehs[c.key].GetMemory()})
}
}
}
fmt.Fprintf(w, "============Start comparing answers!=================\n")
for _, c := range cases {
fmt.Fprintf(w, c.key+"error_sum, query_time(us), memory(KB)\n")
w.Flush()
var (
total_error_sum float64 = 0
total_time float64 = 0
total_memory float64 = 0
)
for i := 0; i < len(GroundTruth[c.key]); i++ {
error_sum := AbsFloat64(GroundTruth[c.key][i].sum-EHAnswer[c.key][i].sum) / GroundTruth[c.key][i].sum
time := EHAnswer[c.key][i].time
memory := EHAnswer[c.key][i].memory
if i%100 == 0 {
// fmt.Fprintf(w, "%f,%f,%f,%f\n", error_count, error_sum, error_sum2, time)
w.Flush()
}
total_error_sum += error_sum
total_time += time
total_memory += memory
}
fmt.Fprintf(w, "Average error, time, memory: avg_sum_error: %f%%, avg_time: %f(us), avg_memory: %f(KB)\n", total_error_sum/float64(len(GroundTruth[c.key]))*100, total_time/float64(len(GroundTruth[c.key])), total_memory/float64(len(GroundTruth[c.key])))
w.Flush()
}
w.Flush()
}
func TestEfficientSumInsertAndQuery(t *testing.T) {
runtime.GOMAXPROCS(40)
// constructInputTimeSeriesZipf()
// readPowerDataset()
readGoogleClusterData2009()
fmt.Println("finished construct input time series")
epsilon_input := []float64{0.2, 0.1, 0.05, 0.01, 0.005, 0.001, 0.0001, 0.00001}
time_window_size_input := []int64{100, 1000, 10000, 100000, 1000000}
var wg sync.WaitGroup
var ops uint64 = 0
var add uint64 = 1
for _, time_window_size := range time_window_size_input {
item_window_size := time_window_size
for _, epsilon := range epsilon_input {
atomic.AddUint64(&ops, add)
for {
if ops < 25 {
break
}
}
testname := fmt.Sprintf("EfficientSum_%d_%f_google", time_window_size, epsilon)
f, err := os.OpenFile("./microbenchmark_results/"+testname+".txt", os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
panic(err)
}
defer f.Close()
wg.Add(1)
go func(epsilon float64, item_window_size int64, time_window_size int64) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
fmt.Printf("=================>Testing epsilon=%f, window_size=%d===================>\n", epsilon, time_window_size)
w := bufio.NewWriter(f)
fmt.Fprintf(w, "=================>Testing epsilon=%f, window_size=%d===================>\n", epsilon, time_window_size)
w.Flush()
GroundTruth := calcGroundTruthSUM2(time_window_size, w)
funcEfficientSum(epsilon, item_window_size, time_window_size, GroundTruth, w)
w.Flush()
atomic.AddUint64(&ops, -add)
wg.Done()
}(epsilon, item_window_size, time_window_size)
}
}
wg.Wait()
}
func funcEfficientSumSubWindow(epsilon float64, item_window_size int64, time_window_size int64, GroundTruth map[string]([]AnswerSum2), w *bufio.Writer, start_t, end_t int64) {
fmt.Fprintf(w, "=================>Estimating with Efficient Sum===================>\n")
w.Flush()
t1 := int64(start_t)
t2 := int64(end_t)
ehs := make(map[string](*EfficientSum))
for _, c := range cases {
ehs[c.key] = NewEfficientSum(item_window_size, time_window_size, epsilon, value_scale)
}
EHAnswer := make(map[string]([]AnswerSum2))
for _, c := range cases {
EHAnswer[c.key] = make([]AnswerSum2, 0)
}
for t := int64(0); t < time_window_size*2; t++ {
for _, c := range cases {
ehs[c.key].Insert(c.vec[t].T, c.vec[t].F)
if t >= time_window_size {
start := time.Now()
ans_sum := ehs[c.key].Query(t-t2, t-t1, true)
elapsed := time.Since(start)
EHAnswer[c.key] = append(EHAnswer[c.key], AnswerSum2{sum: ans_sum, time: float64(elapsed.Microseconds()), memory: ehs[c.key].GetMemory()})
}
}
}
fmt.Fprintf(w, "============Start comparing answers!=================\n")
for _, c := range cases {
fmt.Fprintf(w, c.key+"error_sum, query_time(us), memory(KB)\n")
w.Flush()
var (
total_error_sum float64 = 0
total_time float64 = 0
total_memory float64 = 0
)
for i := 0; i < len(GroundTruth[c.key]); i++ {
error_sum := AbsFloat64(GroundTruth[c.key][i].sum-EHAnswer[c.key][i].sum) / GroundTruth[c.key][i].sum
time := EHAnswer[c.key][i].time
memory := EHAnswer[c.key][i].memory
if i%100 == 0 {
// fmt.Fprintf(w, "%f,%f,%f,%f\n", error_count, error_sum, error_sum2, time)
w.Flush()
}
total_error_sum += error_sum
total_time += time
total_memory += memory
}
fmt.Fprintf(w, "Average error, time, memory: avg_sum_error: %f%%, avg_time: %f(us), avg_memory: %f(KB)\n", total_error_sum/float64(len(GroundTruth[c.key]))*100, total_time/float64(len(GroundTruth[c.key])), total_memory/float64(len(GroundTruth[c.key])))
w.Flush()
}
w.Flush()
}
func TestEfficientSumInsertAndQuerySubWindow(t *testing.T) {
runtime.GOMAXPROCS(40)
// constructInputTimeSeriesZipf()
// readPowerDataset()
// constructInputTimeSeriesUniformFloat64()
readPowerDataset()
// constructInputTimeSeriesUniformFloat64()
// readGoogleClusterData2009()
fmt.Println("finished construct input time series")
epsilon_input := []float64{0.2, 0.1, 0.05, 0.01, 0.005, 0.001, 0.0001, 0.00001}
time_window_size_input := []int64{1000000}
subwindow_size_input := []Pair{{333333, 666666}, {0, 100000}, {0, 200000}, {0, 300000}, {0, 400000}, {0, 500000}, {0, 600000}, {0, 700000}, {0, 800000}, {0, 900000}}
var wg sync.WaitGroup
var ops uint64 = 0
var add uint64 = 1
for _, time_window_size := range time_window_size_input {
item_window_size := time_window_size
for _, subwindow_size := range subwindow_size_input {
for _, epsilon := range epsilon_input {
atomic.AddUint64(&ops, add)
for {
if ops < 40 {
break
}
}
testname := fmt.Sprintf("EfficientSum_%d_%f_%d_%d_power", time_window_size, epsilon, time_window_size-subwindow_size.start, time_window_size-subwindow_size.end)
f, err := os.OpenFile("./microbenchmark_results/"+testname+".txt", os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
panic(err)
}
defer f.Close()
wg.Add(1)
go func(epsilon float64, item_window_size int64, time_window_size int64, start_t, end_t int64) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
fmt.Printf("=================>Testing epsilon=%f, window_size=%d, start_t=%d, end_t=%d===================>\n", epsilon, time_window_size, start_t, end_t)
w := bufio.NewWriter(f)
fmt.Fprintf(w, "=================>Testing epsilon=%f, window_size=%d, start_t=%d, end_t=%d===================>\n", epsilon, time_window_size, start_t, end_t)
w.Flush()
GroundTruth := calcGroundTruthSUM2SubWindow(time_window_size, w, start_t, end_t)
funcEfficientSumSubWindow(epsilon, item_window_size, time_window_size, GroundTruth, w, start_t, end_t)
w.Flush()
atomic.AddUint64(&ops, -add)
fmt.Printf("=================>Done epsilon=%f, window_size=%d, start_t=%d, end_t=%d===================>\n", epsilon, time_window_size, start_t, end_t)
wg.Done()
}(epsilon, item_window_size, time_window_size, subwindow_size.start, subwindow_size.end)
}
}
}
wg.Wait()
}