-
Notifications
You must be signed in to change notification settings - Fork 127
/
benchmarks.slide
150 lines (72 loc) · 3.46 KB
/
benchmarks.slide
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
Go language course
Benchmarks for Go programs
01 Jan 2023
Tags: golang, go, benchmarking
Pavel Tišnovský
Red Hat, Inc.
https://github.com/RedHatOfficial/GoCourse
@RedHat
* Sources
- [[https://github.com/RedHatOfficial/GoCourse]]
.image ./common/qr_address.png
* Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/fiveyears.jpg
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/fiveyears.jpg _ 900
* Performance analysis
- very important part of testing
- profiler is part of standard Go tools
- tracer is also part of standard Go tools
* Benchmarks
- part of standard Go tooling
- can be combined with profiling functions and methods
* Simple benchmark for maps
.code benchmarks/map_test.go /^package main/,/^type value/
* First part of benchmark
.code benchmarks/map_test.go /^func BenchmarkInsertIntoPreallocatedMap/,/^}/
* Second part of benchmark
.code benchmarks/map_test.go /^func BenchmarkInsertIntoEmptyMap/,/^}/
* Start benchmark
- go help test
- go test -bench=.
- go test -bench=. -benchtime=1000x
* Timers
- sometimes it is needed to prepare data/config for benchmarks
- and also check output data generated by benchmarks
- setup/cleanup/checks steps are sometimes memory/CPU-intensive operations
- -> would be better not to measure these steps by benchmark
- b.StopTimer()
- b.StartTimer()
* Large structures
.code benchmarks/parameter_value_reference/conf/config.go /^type Config/,/^}/
* Large structures (2)
.code benchmarks/parameter_value_reference/conf/config.go /^type StorageConfiguration/,/^}/
* Large structures (3)
.code benchmarks/parameter_value_reference/conf/config.go /^type KafkaConfiguration/,/^}/
* Large structures (4)
.code benchmarks/parameter_value_reference/conf/config.go /^func GetStorageConfigurationByValue/,/^}/
.code benchmarks/parameter_value_reference/conf/config.go /^func GetStorageConfigurationByReference/,/^}/
.code benchmarks/parameter_value_reference/conf/config.go /^func \(configuration ConfigStruct\) GetStorageConfigurationByValue/,/^}/
.code benchmarks/parameter_value_reference/conf/config.go /^func \(configuration \*ConfigStruct\) GetStorageConfigurationByReference/,/^}/
* Passing by value/reference (1)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^package conf_test/,/^func loadConfiguration/
* Passing by value/reference (2)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationFunctionByValue/,/^}/
* Passing by value/reference (3)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationFunctionByReference/,/^}/
* Passing by value/reference (4)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationMethodByValue/,/^}/
* Passing by value/reference (5)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationMethodByReference/,/^}/
* Memory profile
- go test -bench=. -benchmem -memprofile profile.out
- go tool pprof profile.out
- go tool pprof -web profile.out
- go tool pprof -http localhost:8080 profile.out
* CPU profile
- go test -bench=. -benchmem -cpuprofile profile.out
- go tool pprof profile.out
- go tool pprof -web profile.out
- go tool pprof -http localhost:8080 profile.out