-
Notifications
You must be signed in to change notification settings - Fork 59
/
message_benchmark_test.go
68 lines (57 loc) · 1.31 KB
/
message_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
package twitch
import (
"bufio"
"compress/gzip"
"fmt"
"os"
"runtime"
"testing"
)
var messages []string
func TestMain(m *testing.M) {
messages = readLog("./test_resources/channel.txt.gz")
os.Exit(m.Run())
}
func BenchmarkParseBigLog(b *testing.B) {
for n := 0; n < b.N; n++ {
for _, line := range messages {
ParseMessage(line)
}
}
}
func BenchmarkParseWHISPERMessage(b *testing.B) {
testMessage := "@badges=;color=#00FF7F;display-name=Danielps1;emotes=;message-id=20;thread-id=32591953_77829817;turbo=0;user-id=32591953;user-type= :danielps1!danielps1@danielps1.tmi.twitch.tv WHISPER gempir :i like memes"
for n := 0; n < b.N; n++ {
ParseMessage(testMessage)
}
}
func BenchmarkParseMessageType(b *testing.B) {
testCommand := "RECONNECT"
for n := 0; n < b.N; n++ {
parseMessageType(testCommand)
}
}
func readLog(logFile string) []string {
f, err := os.Open(logFile)
if err != nil {
fmt.Println("logFile not found")
runtime.Goexit()
}
defer f.Close()
gz, err := gzip.NewReader(f)
if err != nil {
fmt.Println("logFile gzip not readable")
runtime.Goexit()
}
scanner := bufio.NewScanner(gz)
if err != nil {
fmt.Println("logFile not readable")
runtime.Goexit()
}
content := []string{}
for scanner.Scan() {
line := scanner.Text()
content = append(content, line)
}
return content
}