forked from RedHatOfficial/GoCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks_ru.slide
More file actions
159 lines (78 loc) · 4.52 KB
/
benchmarks_ru.slide
File metadata and controls
159 lines (78 loc) · 4.52 KB
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
156
157
158
159
Курс языка Go
Бенчмарки для программ Go
01 Jan 2023
Tags: golang, go, benchmarking
Pavel Tišnovský
Red Hat, Inc.
ptisnovs@redhat.com
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
* Анализ производительности
- очень важная часть тестирования
- профилировщик входит в стандартные инструменты Go
- трейсер также входит в стандартные инструменты Go
* Бенчмарки
- часть стандартных инструментов Go
- могут комбинироваться с функциями и методами профилирования
* Простой бенчмарк для карт
.code benchmarks/map_test.go /^package main/,/^type value/
* Первая часть бенчмарка
.code benchmarks/map_test.go /^func BenchmarkInsertIntoPreallocatedMap/,/^}/
* Вторая часть бенчмарка
.code benchmarks/map_test.go /^func BenchmarkInsertIntoEmptyMap/,/^}/
* Запуск бенчмарка
- go help test
- go test -bench=.
- go test -bench=. -benchtime=1000x
* Таймеры
- иногда необходимо подготовить данные/конфигурацию для бенчмарков
- а также проверить выходные данные, генерируемые бенчмарками
- шаги настройки/очистки/проверки иногда являются ресурсоемкими операциями
- -> лучше не измерять эти шаги в бенчмарке
- b.StopTimer()
- b.StartTimer()
* Большие структуры
.code benchmarks/parameter_value_reference/conf/config.go /^type Config/,/^}/
* Большие структуры (2)
.code benchmarks/parameter_value_reference/conf/config.go /^type StorageConfiguration/,/^}/
* Большие структуры (3)
.code benchmarks/parameter_value_reference/conf/config.go /^type KafkaConfiguration/,/^}/
* Большие структуры (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/,/^}/
* Передача по значению/ссылке (1)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^package conf_test/,/^func loadConfiguration/
* Передача по значению/ссылке (2)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationFunctionByValue/,/^}/
* Передача по значению/ссылке (3)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationFunctionByReference/,/^}/
* Передача по значению/ссылке (4)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationMethodByValue/,/^}/
* Передача по значению/ссылке (5)
.code benchmarks/parameter_value_reference/conf/config_benchmark_test.go /^func BenchmarkGetStorageConfigurationMethodByReference/,/^}/
* Профиль памяти
- 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
- 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
#last slide
* Больше Gophers
#The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/)
#Source https://golang.org/doc/gopher/bumper.png
#The design and this image is licensed under the Creative Commons 3.0 Attributions license.
.image ./common/bumper.png _ 900