forked from devfeel/dotweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstate_test.go
82 lines (71 loc) · 1.52 KB
/
state_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
package dotweb
import (
"testing"
)
// 以下为功能测试
func Test_AddRequestCount_1(t *testing.T) {
var num uint64 = 1
var count uint64
for i := 0; i < 100; i++ {
count = GlobalState.AddRequestCount(num)
}
t.Log("TotalRequestCount:", count)
}
func Test_AddRequestCount_2(t *testing.T) {
var num uint64 = 1
var count uint64
for i := 0; i < 100; i++ {
count = GlobalState.AddRequestCount(num)
num++
}
t.Log("TotalRequestCount:", count)
}
func Test_AddErrorCount_1(t *testing.T) {
var num, count uint64
for i := 0; i < 100; i++ {
num = 1
count = GlobalState.AddErrorCount(num)
}
t.Log("TotalErrorCount:", count)
}
func Test_AddErrorCount_2(t *testing.T) {
var num, count uint64
for i := 0; i < 100; i++ {
count = GlobalState.AddErrorCount(num)
num++
}
t.Log("TotalErrorCount:", count)
}
// 以下是性能测试
//基准测试
func Benchmark_AddErrorCount_1(b *testing.B) {
var num uint64 = 1
for i := 0; i < b.N; i++ {
GlobalState.AddErrorCount(num)
}
}
// 测试并发效率
func Benchmark_AddErrorCount_Parallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var num uint64 = 1
for pb.Next() {
GlobalState.AddErrorCount(num)
}
})
}
//基准测试
func Benchmark_AddRequestCount_1(b *testing.B) {
var num uint64 = 1
for i := 0; i < b.N; i++ {
GlobalState.AddRequestCount(num)
}
}
// 测试并发效率
func Benchmark_AddRequestCount_Parallel(b *testing.B) {
b.RunParallel(func(pb *testing.PB) {
var num uint64 = 1
for pb.Next() {
GlobalState.AddRequestCount(num)
}
})
}