-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmarks_test.go
55 lines (50 loc) · 1.09 KB
/
benchmarks_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
package bigbro
import (
"bytes"
"encoding/json"
"fmt"
"math/rand"
"testing"
"time"
)
func BenchmarkCSVLogging(b *testing.B) {
logger, err := NewCSVLogger(fmt.Sprintf("/tmp/bb_%s.log", time.Now().Format(time.RFC3339)))
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
// We create a random event.
event := Event{
Target: "window",
Name: "",
ID: "",
Method: "click",
Location: "https://example.com",
Comment: "",
X: rand.Int(),
Y: rand.Int(),
ScreenWidth: 1000,
ScreenHeight: 1000,
Time: time.Now(),
Actor: "A1",
}
// Encode and decode the event to simulate it coming over the wire.
var j bytes.Buffer
err := json.NewEncoder(&j).Encode(event)
if err != nil {
b.Fatal(err)
}
var sentEvent Event
err = json.NewDecoder(&j).Decode(&sentEvent)
if err != nil {
b.Fatal(err)
}
b.SetBytes(int64(len(logger.formatter.Format(sentEvent))))
// Finally, log the event.
err = logger.Log(sentEvent)
if err != nil {
b.Fatal(err)
}
}
}