summaryrefslogtreecommitdiff
path: root/public/posts/2024-08-25-01.html
blob: a678b9241425a050b46b29ae61f6ec9d392d44b1 (plain)
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

<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="description" content="Home for a73x" />
	<meta name="author" content="a73x" />
	<meta name="viewport"
		content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, width=device-width" />
	<title>a73x</title>
	<link rel="stylesheet" href="/static/styles.css">
	<link rel="stylesheet" href="/static/syntax.css">
	<link rel="icon" type="image/x-icon" href="/static/favicon.svg">
</head>

<body>
	<main>
		<div class="header">
			<div class="header-title">
				<h1>a73x</h1>
				<sub>high effort, low reward</sub>
			</div>
			<nav class="nav">
				<ul>
					
					
					<li><a class="no-decorations" href="/">Home</a></li>
					
					
					
					<li><a class="no-decorations" href="/posts">Posts</a></li>
					
					
					
					<li><a class="no-decorations" href="/ethos">Ethos</a></li>
					
					
				</ul>
			</nav>
		</div>
			<hr />
		
<a href="/posts">← Posts</a>
<h1>Go Benchmarking</h1>
<h1 id="table-of-contents">Table of Contents</h1>
<ul>
<li>
<a href="#cpuprofile">cpuprofile</a></li>
<li>
<a href="#memprofile">memprofile</a></li>
<li>
<a href="#pprof">pprof</a><ul>
<li>
<a href="#views">views</a></li>
</ul>
</li>
</ul>
<p>The benchmark cycle:</p>
<ol>
<li>write a benchmark</li>
<li>run a benchmark</li>
<li>get a profile</li>
<li>optimise</li>
<li>run your tests</li>
<li>goto 2.</li>
</ol>
<h2 id="cpuprofile">cpuprofile</h2>
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;white-space:pre-wrap;word-break:break-word;"><code>go <span style="color:#0aa">test</span> -test=XXX -bench &lt;regex&gt; -cpuprofile &lt;file&gt;
</code></pre><h2 id="memprofile">memprofile</h2>
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;white-space:pre-wrap;word-break:break-word;"><code>go <span style="color:#0aa">test</span> -test=XXX -bench &lt;regex&gt; -memprofile &lt;file&gt; -benchmem
</code></pre><h2 id="pprof">pprof</h2>
<p><a href="https://github.com/google/pprof/blob/main/doc/README.md">pprof usage</a></p>
<pre tabindex="0" style="background-color:#f0f0f0;-moz-tab-size:4;-o-tab-size:4;tab-size:4;white-space:pre-wrap;word-break:break-word;"><code>go pprof -http=:8080 profile.pb.gz
</code></pre><p>will show a web UI for analysing the profile.</p>
<h3 id="views">views</h3>
<ul>
<li>flame graph: <code>localhost:8080/ui/flamegraph</code>
<ul>
<li>shows percentage breakdown of how much resource each &quot;call&quot; made.</li>
<li>clicking a box will make it &quot;100%&quot; allowing for deep diving</li>
<li>right click &quot;show source code&quot; to view</li>
</ul>
</li>
<li>top: <code>localhost:8080/ui/top</code>
<ul>
<li>shows top functions
<ul>
<li><code>flat</code>: profile samples in this function</li>
<li><code>cum</code>: (cumulative) profile samples in this function and its callees</li>
</ul>
</li>
</ul>
</li>
<li>source: <code>localhost:8080/ui/source</code>
<ul>
<li>each source line is annotated with the time spent in that source line
<ul>
<li>the first number does not count time spent in functions called from the source line</li>
<li>the second number does</li>
</ul>
</li>
</ul>
</li>
</ul>


		<footer>
			<br />
			<hr />
			​​​​​​​​​​​​​​​​​​​<br />​
			<p>see something you disagree with? email: <a href="mailto:[email protected]">[email protected]</a></p>
		</footer>
	</main>
</body>

</html>