You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/golang-on-azure/benchmarking.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,12 +1,12 @@
1
1
---
2
-
title: Perform Benchmark using go test -bench
2
+
title: Run performance tests using go test -bench
3
3
weight: 6
4
4
5
5
### FIXED, DO NOT MODIFY
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Run performance tests using go test -bench
9
+
## Performance benchmarking with Go's built-in testing framework
10
10
11
11
`go test -bench` is Go’s built-in benchmark runner. It repeatedly executes benchmark functions and reports latency (ns/op). With the `-benchmem` flag, it also reports memory usage (B/op) and allocations (allocs/op). It’s simple, reliable, and requires only writing benchmark functions in the standard Golang testing package.
12
12
@@ -24,7 +24,7 @@ Initialize a new module:
24
24
```console
25
25
go mod init gosort-bench
26
26
```
27
-
This creates a `go.mod` file, which defines the module path (gosort-bench in this case) and marks the directory as a Go project. The `go.mod` file also allows Go to manage dependencies (external libraries) automatically, ensuring your project remains reproducible and easy to maintain.
27
+
This creates a `go.mod` file, which defines the module path (`gosort-bench` in this case) and marks the directory as a Go project. The `go.mod` file also allows Go to manage dependencies (external libraries) automatically, ensuring your project remains reproducible and easy to maintain.
28
28
29
29
## Add sorting functions
30
30
@@ -72,10 +72,10 @@ func partition(arr []int, low, high int) int {
72
72
return i + 1
73
73
}
74
74
```
75
-
The code contains two sorting methods, Bubble Sort and Quick Sort, which arrange numbers in order from smallest to largest:
75
+
The code contains two sorting methods, *Bubble Sort* and *Quick Sort*, which arrange numbers in order from smallest to largest:
76
76
77
-
- Bubble Sort works by repeatedly comparing two numbers side by side and swapping them if they are in the wrong order. It keeps doing this until the whole list is sorted.
78
-
- Quick Sort is faster. It picks a pivot number and splits the list into two groups. Numbers smaller than the pivot and numbers bigger than it. Then it sorts each group separately. The function partition helps Quick Sort decide where to split the list based on the pivot number.
77
+
-*Bubble Sort* works by repeatedly comparing two numbers side by side and swapping them if they are in the wrong order. It keeps doing this until the whole list is sorted.
78
+
-*Quick Sort* is faster. It picks a pivot number and splits the list into two groups. Numbers smaller than the pivot and numbers bigger than it. Then it sorts each group separately. The function partition helps Quick Sort decide where to split the list based on the pivot number.
79
79
80
80
To summarize, Bubble Sort is simple but slow, while Quick Sort is more efficient and usually much faster for big lists of numbers.
81
81
@@ -133,7 +133,7 @@ The code implements a benchmark that measures the performance of Bubble Sort and
133
133
134
134
When you run the benchmark, Go will show you how long each sort takes and how much memory it uses, so you can compare the two sorting techniques.
135
135
136
-
###Run the Benchmark
136
+
## Run the Benchmark
137
137
138
138
Execute the benchmark suite using the following command:
139
139
```console
@@ -156,9 +156,9 @@ ok gosort-bench 2.905s
156
156
157
157
The metrics reported by go test -bench include ns/op, which measures nanoseconds per operation and reflects latency where lower values are better, B/op, which shows the number of bytes allocated per operation and helps identify memory efficiency, and allocs/op, which indicates the number of heap allocations per operation and highlights how often memory is being allocated, with lower values preferred in all cases.
158
158
159
-
###Benchmark summary on Arm64
159
+
## Benchmark summary on Arm64
160
160
161
-
Results collected on an Arm64 **D4ps_v6** Ubuntu Pro 24.04 LTS virtual machine:
161
+
Results collected on an Arm64 D4ps_v6 Ubuntu Pro 24.04 LTS virtual machine:
162
162
163
163
| Benchmark | Value |
164
164
|----------------------|-------|
@@ -172,7 +172,7 @@ Results collected on an Arm64 **D4ps_v6** Ubuntu Pro 24.04 LTS virtual machine:
172
172
173
173
## Benchmark summary on x86-64
174
174
175
-
Results collected on an x86-64 **D4s_v6** Ubuntu Pro 24.04 LTS virtual machine:
175
+
Results collected on an x86-64 D4s_v6 Ubuntu Pro 24.04 LTS virtual machine:
0 commit comments