Skip to content

Commit fae46f9

Browse files
Standardize title casing and improve section headings for clarity in baseline testing and benchmarking documentation
1 parent 9d25c74 commit fae46f9

2 files changed

Lines changed: 45 additions & 55 deletions

File tree

content/learning-paths/servers-and-cloud-computing/golang-on-azure/baseline-testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Golang Baseline Testing
2+
title: Golang baseline testing
33
weight: 5
44

55
### FIXED, DO NOT MODIFY

content/learning-paths/servers-and-cloud-computing/golang-on-azure/benchmarking.md

Lines changed: 44 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
11
---
2-
title: Benchmarking via go test -bench
2+
title: Benchmarking using go test -bench
33
weight: 6
44

55
### FIXED, DO NOT MODIFY
66
layout: learningpathall
77
---
88

9-
## Run Performance Tests Using go test -bench
9+
## Run performance tests using go test -bench
1010

11-
`go test -bench` (the benchmarking mode of go test) is Golang’s built-in benchmarking framework that measures the performance of functions by running them repeatedly and reporting execution time (**ns/op**), memory usage, and allocations. With the `-benchmem flag`, it also shows memory usage and allocations. It’s simple, reliable, and requires only writing benchmark functions in the standard Golang testing package.
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.
1212

13-
1. Create a Project Folder
14-
15-
In your terminal, create a directory for your benchmark project and navigate into it:
13+
## Create a project folder
1614

15+
Create a directory for your benchmark project and navigate to it:
1716
```console
1817
mkdir gosort-bench
1918
cd gosort-bench
2019
```
2120

22-
2. Initialize a Go Module
23-
24-
Inside your project directory, initialize a new Go module by running:
21+
## Initialize a Go module
2522

23+
Initialize a new module:
2624
```console
2725
go mod init gosort-bench
2826
```
2927
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.
3028

31-
3. Add Sorting Functions
32-
33-
Create a file called `sorting.go`:
29+
## Add sorting functions
3430

31+
Create a file named `sorting.go`:
3532
```console
3633
nano sorting.go
3734
```
38-
Paste the following code in `sorting.go`:
3935

36+
Paste the following implementation into `sorting.go`:
4037
```go
4138
package sorting
4239
func BubbleSort(arr []int) {
@@ -75,9 +72,10 @@ func partition(arr []int, low, high int) int {
7572
return i + 1
7673
}
7774
```
78-
The code contains two sorting methods, Bubble Sort and Quick Sort, which arrange numbers in order from smallest to largest.
79-
* 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.
80-
* 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.
75+
The code contains two sorting methods, Bubble Sort and Quick Sort, which arrange numbers in order from smallest to largest:
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.
8179

8280
To summarize, Bubble Sort is simple but slow, while Quick Sort is more efficient and usually much faster for big lists of numbers.
8381

@@ -90,16 +88,14 @@ mkdir sorting
9088
mv sorting.go sorting/
9189
```
9290

93-
4. Add Benchmark Tests
94-
95-
Next, create a benchmark test file named `sorting_benchmark_test.go` in your project’s root directory (not inside the sorting/ folder, so it can import the sorting package cleanly):
91+
### Add benchmark tests
9692

93+
Create a benchmark file named `sorting_benchmark_test.go` in the project root:
9794
```console
9895
nano sorting_benchmark_test.go
99-
````
100-
101-
Paste the following code into it:
96+
```
10297

98+
Paste the following code:
10399
```go
104100
package sorting_test
105101
import (
@@ -133,10 +129,7 @@ func BenchmarkQuickSort(b *testing.B) {
133129
}
134130
}
135131
```
136-
The code implements a benchmark that checks how fast Bubble Sort and Quick Sort run in Go.
137-
- It first creates a list of 10,000 random numbers each time before running a sort, so the test is fair and consistent.
138-
- The BenchmarkBubbleSort() function measures the speed of sorting using the slower Bubble Sort method.
139-
- The BenchmarkQuickSort() function measures the speed of sorting using the faster Quick Sort method.
132+
The code implements a benchmark that measures the performance of Bubble Sort and Quick Sort in Go by generating a new list of 10,000 random numbers before each run to keep the test fair and consistent. The BenchmarkBubbleSort() function evaluates the slower Bubble Sort algorithm, while the BenchmarkQuickSort() function evaluates the faster Quick Sort algorithm, allowing you to compare their relative speeds and efficiency.
140133

141134
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.
142135

@@ -146,11 +139,9 @@ Execute the benchmark suite using the following command:
146139
```console
147140
go test -bench=. -benchmem
148141
```
149-
-bench=. runs every function whose name starts with Benchmark.
150-
-benchmem adds memory metrics (B/op, allocs/op) to the report.
151-
152-
You should see output similar to:
142+
`-bench=.` runs every function whose name starts with `Benchmark`. `-benchmem` adds memory metrics (B/op, allocs/op) to the report.
153143

144+
Expected output:
154145
```output
155146
goos: linux
156147
goarch: arm64
@@ -160,27 +151,30 @@ BenchmarkQuickSort-4 3506 340873 ns/op 0
160151
PASS
161152
ok gosort-bench 2.905s
162153
```
163-
### Metrics Explained
164154

165-
* ns/op – nanoseconds per operation (lower is better). This is the primary latency metric.
166-
* B/op – bytes allocated per operation (lower is better). This is useful for spotting hidden allocations.
167-
* allocs/op – number of heap allocations per operation (lower is better). Zero here means the algorithm itself didn’t allocate.
168-
155+
### Metrics explained
156+
157+
- ns/op: nanoseconds per operation (lower is better)
158+
- B/op: bytes allocated per operation (lower is better)
159+
- allocs/op: number of heap allocations per operation (lower is better)
160+
169161
### Benchmark summary on Arm64
170-
Here is a summary of benchmark results collected on an Arm64 D4ps_v6 Ubuntu Pro 24.04 LTS virtual machine.
171162

172-
| Benchmark | Value on Virtual Machine |
173-
|-------------------|--------------------------|
174-
| BubbleSort (ns/op) | 36,616,759 |
175-
| QuickSort (ns/op) | 340,873 |
176-
| BubbleSort runs | 32 |
177-
| QuickSort runs | 3,506 |
178-
| Allocations/op | 0 |
179-
| Bytes/op | 0 |
180-
| Total time (s) | 2.905 |
163+
Results collected on an Arm64 **D4ps_v6** Ubuntu Pro 24.04 LTS virtual machine:
181164

182-
### Benchmark summary on x86_64
183-
Here is a summary of the benchmark results collected on x86_64 D4s_v6 Ubuntu Pro 24.04 LTS virtual machine.
165+
| Benchmark | Value |
166+
|----------------------|-------|
167+
| BubbleSort (ns/op) | 36,616,759 |
168+
| QuickSort (ns/op) | 340,873 |
169+
| BubbleSort runs | 32 |
170+
| QuickSort runs | 3,506 |
171+
| Allocations/op | 0 |
172+
| Bytes/op | 0 |
173+
| Total time (s) | 2.905 |
174+
175+
## Benchmark summary on x86-64
176+
177+
Results collected on an x86-64 **D4s_v6** Ubuntu Pro 24.04 LTS virtual machine:
184178

185179
| Benchmark | Value on Virtual Machine |
186180
|-------------------|--------------------------|
@@ -193,12 +187,8 @@ Here is a summary of the benchmark results collected on x86_64 D4s_v6 Ubuntu Pro
193187
| Total time (s) | 2.716 |
194188

195189

196-
### Benchmarking comparison summary
197-
198-
When you compare the benchmarking results you will notice that on the Azure Cobalt 100:
199-
200-
Azure Cobalt 100 (Arm64) outperforms in both BubbleSort and QuickSort benchmarks, with the advantage more pronounced for QuickSort. The performance delta (~15–33%) shows how Arm Neoverse cores deliver strong results in CPU-bound, integer-heavy workloads common in Go applications.
190+
## Benchmarking comparison summary
201191

202-
For real-world Go applications that rely on sorting, JSON processing, and other recursive or data-processing workloads, running on Azure Cobalt 100 Arm64 VMs can deliver better throughput and reduced execution time compared to similarly sized x86_64 VMs.
192+
On Azure Cobalt 100 (Arm64), both BubbleSort and QuickSort run faster, with a larger advantage for QuickSort. The observed performance delta (~15–33%) highlights how Arm Neoverse cores excel at CPU-bound, integer-heavy workloads common in Go services.
203193

204-
These results validate the benefits of running Go workloads on Azure Cobalt 100 Arm64 instances, and establish a baseline for extending benchmarks to real-world workloads beyond sorting.
194+
For real-world Go applications, such as sorting, JSON processing, and other recursive or data-processing tasks, Azure Cobalt 100 Arm64 VMs can provide higher throughput and lower execution time than similarly sized x86-64 VMs. These results validate the benefits of running Go on Cobalt 100 and establish a baseline for extending benchmarks beyond simple sorting.

0 commit comments

Comments
 (0)