-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain_timing_test.go
52 lines (49 loc) · 1.3 KB
/
main_timing_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
package main
import (
"bufio"
"fmt"
"io/ioutil"
"math/rand"
"testing"
"time"
)
func BenchmarkWriteSeriesVMImport(b *testing.B) {
const rowsCount = 24 * 60
const loopsCount = 10
b.ReportAllocs()
b.SetBytes(rowsCount * loopsCount)
b.RunParallel(func(pb *testing.PB) {
startTimestamp := time.Now().UnixNano() / 1e6
bw := bufio.NewWriter(ioutil.Discard)
r := rand.New(rand.NewSource(startTimestamp))
sensorID := int(startTimestamp) % 1e6
for pb.Next() {
for i := 0; i < loopsCount; i++ {
writeSeriesVMImport(bw, r, sensorID, rowsCount, startTimestamp)
}
if err := bw.Flush(); err != nil {
panic(fmt.Errorf("unexpected error on bufio.Writer.Flush: %s", err))
}
}
})
}
func BenchmarkWriteSeriesInflux(b *testing.B) {
const rowsCount = 24 * 60
const loopsCount = 10
b.ReportAllocs()
b.SetBytes(rowsCount * loopsCount)
b.RunParallel(func(pb *testing.PB) {
startTimestamp := time.Now().UnixNano() / 1e6
bw := bufio.NewWriter(ioutil.Discard)
r := rand.New(rand.NewSource(startTimestamp))
sensorID := int(startTimestamp) % 1e6
for pb.Next() {
for i := 0; i < loopsCount; i++ {
writeSeriesInflux(bw, r, sensorID, rowsCount, startTimestamp)
}
if err := bw.Flush(); err != nil {
panic(fmt.Errorf("unexpected error on bufio.Writer.Flush: %s", err))
}
}
})
}