forked from GuanceCloud/datakit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
155 lines (144 loc) · 6.67 KB
/
utils_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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
// Unless explicitly stated otherwise all files in this repository are licensed
// under the MIT License.
// This product includes software developed at Guance Cloud (https://www.guance.com/).
// Copyright 2021-present Guance, Inc.
package datakit
import (
"testing"
"time"
"gitlab.jiagouyun.com/cloudcare-tools/cliutils"
tu "gitlab.jiagouyun.com/cloudcare-tools/cliutils/testutil"
)
func BenchmarkGzipString(b *testing.B) {
data := cliutils.CreateRandomString(1024)
for i := 0; i < b.N; i++ {
_, err := GZipStr(data)
if err != nil {
b.Fatal(err)
}
}
// -------------- mem bench ----------------
// goos: darwin
// goarch: amd64
// pkg: gitlab.jiagouyun.com/cloudcare-tools/datakit
// BenchmarkGzipString-4 4778 237426 ns/op
// PASS
// ok gitlab.jiagouyun.com/cloudcare-tools/datakit 1.722s
// Type: alloc_space
// Time: Mar 24, 2021 at 2:25pm (CST)
// Entering interactive mode (type "help" for commands, "o" for options)
// (pprof) top
// Showing nodes accounting for 5182.03MB, 99.58% of 5204.07MB total
// Dropped 12 nodes (cum <= 26.02MB)
// Showing top 10 nodes out of 18
// flat flat% sum% cum cum%
// 4239.69MB 81.47% 81.47% 5141.93MB 98.81% compress/flate.NewWriter
// 873.72MB 16.79% 98.26% 873.72MB 16.79% compress/flate.(*compressor).initDeflate (inline)
// 46.60MB 0.9% 99.15% 46.60MB 0.9% compress/flate.(*huffmanEncoder).generate
// 16.51MB 0.32% 99.47% 28.52MB 0.55% compress/flate.newHuffmanBitWriter (inline)
// 5.51MB 0.11% 99.58% 5147.44MB 98.91% io.WriteString
// 0 0% 99.58% 54.11MB 1.04% compress/flate.(*Writer).Flush
// 0 0% 99.58% 54.11MB 1.04% compress/flate.(*compressor).deflate
// 0 0% 99.58% 902.25MB 17.34% compress/flate.(*compressor).init
// 0 0% 99.58% 54.11MB 1.04% compress/flate.(*compressor).syncFlush
// 0 0% 99.58% 54.11MB 1.04% compress/flate.(*compressor).writeBlock
// -------------- cpu bench ----------------
// goos: darwin
// goarch: amd64
// pkg: gitlab.jiagouyun.com/cloudcare-tools/datakit
// BenchmarkGzipString-4 4855 229180 ns/op
// PASS
// ok gitlab.jiagouyun.com/cloudcare-tools/datakit 1.849s
//
// Type: cpu
// Time: Mar 24, 2021 at 2:30pm (CST)
// Duration: 1.81s, Total samples = 3.22s (178.10%)
// Entering interactive mode (type "help" for commands, "o" for options)
// (pprof) topo
// unrecognized command: "topo"
// (pprof) top
// Showing nodes accounting for 2730ms, 84.78% of 3220ms total
// Dropped 35 nodes (cum <= 16.10ms)
// Showing top 10 nodes out of 100
// flat flat% sum% cum cum%
// 910ms 28.26% 28.26% 910ms 28.26% runtime.pthread_cond_wait
// 810ms 25.16% 53.42% 810ms 25.16% runtime.kevent
// 290ms 9.01% 62.42% 290ms 9.01% runtime.pthread_kill
// 160ms 4.97% 67.39% 160ms 4.97% runtime.memclrNoHeapPointers
// 160ms 4.97% 72.36% 240ms 7.45% runtime.scanobject
// 120ms 3.73% 76.09% 120ms 3.73% runtime.memmove
// 80ms 2.48% 78.57% 90ms 2.80% runtime.findObject
// 80ms 2.48% 81.06% 80ms 2.48% runtime.pthread_cond_signal
// 60ms 1.86% 82.92% 60ms 1.86% runtime.madvise
// 60ms 1.86% 84.78% 70ms 2.17% runtime.nanotime1
}
func BenchmarkGzipBytes(b *testing.B) {
data := cliutils.CreateRandomString(1024)
for i := 0; i < b.N; i++ {
_, err := GZip([]byte(data))
if err != nil {
b.Fatal(err)
}
}
// goos: darwin
// goarch: amd64
// pkg: gitlab.jiagouyun.com/cloudcare-tools/datakit
// BenchmarkGzipBytes-4 5211 245549 ns/op
// PASS
// ok gitlab.jiagouyun.com/cloudcare-tools/datakit 2.834s
// Mac :) (doc-integration) gtp mem.out
// Type: alloc_space
// Time: Mar 24, 2021 at 2:26pm (CST)
// Entering interactive mode (type "help" for commands, "o" for options)
// (pprof) top
// Showing nodes accounting for 8.46GB, 99.54% of 8.49GB total
// Dropped 28 nodes (cum <= 0.04GB)
// Showing top 10 nodes out of 17
// flat flat% sum% cum cum%
// 6.90GB 81.20% 81.20% 8.39GB 98.72% compress/flate.NewWriter
// 1.44GB 17.00% 98.20% 1.44GB 17.00% compress/flate.(*compressor).initDeflate (inline)
// 0.07GB 0.87% 99.07% 0.07GB 0.87% compress/flate.(*huffmanEncoder).generate
// 0.02GB 0.28% 99.34% 0.04GB 0.52% compress/flate.newHuffmanBitWriter (inline)
// 0.02GB 0.2% 99.54% 8.49GB 100% gitlab.jiagouyun.com/cloudcare-tools/datakit.BenchmarkGzipBytes
// 0 0% 99.54% 0.09GB 1.04% compress/flate.(*Writer).Flush (inline)
// 0 0% 99.54% 0.09GB 1.04% compress/flate.(*compressor).deflate
// 0 0% 99.54% 1.49GB 17.52% compress/flate.(*compressor).init
// 0 0% 99.54% 0.09GB 1.04% compress/flate.(*compressor).syncFlush
// 0 0% 99.54% 0.09GB 1.04% compress/flate.(*compressor).writeBlock
// ---------------- cpu bench ----------------
// goos: darwin
// goarch: amd64
// pkg: gitlab.jiagouyun.com/cloudcare-tools/datakit
// BenchmarkGzipBytes-4 4754 234517 ns/op
// PASS
// ok gitlab.jiagouyun.com/cloudcare-tools/datakit 1.992s
//
// Type: cpu
// Time: Mar 24, 2021 at 2:33pm (CST)
// Duration: 1.90s, Total samples = 3.29s (172.73%)
// Entering interactive mode (type "help" for commands, "o" for options)
// (pprof) top
// Showing nodes accounting for 2880ms, 87.54% of 3290ms total
// Dropped 36 nodes (cum <= 16.45ms)
// Showing top 10 nodes out of 111
// flat flat% sum% cum cum%
// 1090ms 33.13% 33.13% 1090ms 33.13% runtime.pthread_cond_wait
// 700ms 21.28% 54.41% 700ms 21.28% runtime.kevent
// 240ms 7.29% 61.70% 240ms 7.29% runtime.pthread_kill
// 210ms 6.38% 68.09% 210ms 6.38% runtime.pthread_cond_signal
// 200ms 6.08% 74.16% 280ms 8.51% runtime.scanobject
// 120ms 3.65% 77.81% 120ms 3.65% runtime.memclrNoHeapPointers
// 110ms 3.34% 81.16% 110ms 3.34% runtime.pthread_cond_timedwait_relative_np
// 80ms 2.43% 83.59% 80ms 2.43% runtime.usleep
// 70ms 2.13% 85.71% 70ms 2.13% runtime.memmove
// 60ms 1.82% 87.54% 60ms 1.82% runtime.madvise
}
func TestDuration(t *testing.T) {
d := Duration{Duration: time.Second}
tu.Equals(t, "1s", d.UnitString(time.Second))
tu.Equals(t, "1000000000ns", d.UnitString(time.Nanosecond))
tu.Equals(t, "1000000mics", d.UnitString(time.Microsecond))
tu.Equals(t, "1000ms", d.UnitString(time.Millisecond))
tu.Equals(t, "0m", d.UnitString(time.Minute))
tu.Equals(t, "0h", d.UnitString(time.Hour))
}