-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbenchmar_test.go
123 lines (101 loc) · 2.58 KB
/
benchmar_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
119
120
121
122
123
package main
import (
"crypto/md5"
"fmt"
"regexp"
"testing"
"github.com/segmentio/fasthash/fnv1a"
)
const str = `00:03.869001-2998,CALL,2,process=rphost,p:processName=hrmcorp-n29,OSThread=8389,t:clientID=30190,t:applicationName=1CV8C,t:computerName=CA-TEST-RDP-1,t:connectID=331409,callWait=0,Usr=Парма,SessionID=533,Context=Система.ПолучитьИзВременногоХранилища,Interface=bc15bd01-10bf-413c-a856-ddc907fcd123,IName=IVResourceRemoteConnection,Method=0,CallID=25058,MName=send,Memory=-8208,MemoryPeak=589904,InBytes=0,OutBytes=0,CpuTime=1357 `
func BenchmarkRegexp(b *testing.B) {
for i := 0; i < b.N; i++ {
re := regexp.MustCompile(`(?mi)\d\d:\d\d\.\d+[-]\d+`)
re.MatchString(str)
}
}
func BenchmarkGetHashWithRace(b *testing.B) {
for i := 0; i < b.N; i++ {
getHashWitRace(str)
}
}
func BenchmarkGetFastHashWithRace(b *testing.B) {
for i := 0; i < b.N; i++ {
getFastHashWitRace(str)
}
}
func BenchmarkGetHashWithoutRace(b *testing.B) {
for i := 0; i < b.N; i++ {
getHashWithoutRace(str)
}
}
func BenchmarkGetFastHashWithoutRace(b *testing.B) {
for i := 0; i < b.N; i++ {
getFastHashWithoutRace(str)
}
}
func BenchmarkParseString(b *testing.B) {
formatter := new(formatter1C)
for i := 0; i < b.N; i++ {
formatter.Format(str)
}
}
func BenchmarkGetHashWitWorkers(b *testing.B) {
//workersIn := make(chan string, 0)
//workersOut := make(chan string, 0)
//
//for i := 0; i < b.N; i++ {
// workersIn <- str
//}
//
//for i:=0; i<10; i++ {
// go func() {
// for s := range workersIn {
// Sum := md5.Sum([]byte(s))
// workersOut <- fmt.Sprintf("%x", Sum)
// }
// }()
//}
//
//for range workersOut {
//
//}
}
func getHashWithoutRace(s string) string {
Sum := md5.Sum([]byte(s))
return fmt.Sprintf("%x", Sum)
}
func getHashWitRace(inStr string) string {
out := make(chan string)
// race pattern
sumString := func() {
Sum := md5.Sum([]byte(inStr))
out <- fmt.Sprintf("%x", Sum)
}
// работа на опережедние
go sumString()
go sumString()
go sumString()
return <-out
}
func getHashWitWorkers(s string) string {
Sum := md5.Sum([]byte(s))
return fmt.Sprintf("%x", Sum)
}
func getFastHashWitRace(inStr string) string {
out := make(chan string)
// race pattern
sumString := func() {
Sum := fnv1a.HashString64(inStr)
out <- fmt.Sprintf("%x", Sum)
}
// работа на опережедние
go sumString()
go sumString()
go sumString()
return <-out
}
func getFastHashWithoutRace(s string) string {
Sum := fnv1a.HashString64(s)
return fmt.Sprintf("%x", Sum)
}
// go test . -test.bench .*