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/rust-on-gcp/benchmarking.md
+12-34Lines changed: 12 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,11 +6,11 @@ weight: 6
6
6
layout: learningpathall
7
7
---
8
8
9
-
## Benchmark Rust performance
9
+
## Overview
10
10
11
-
This section demonstrates how to benchmark Rust performance using `cargo bench` and the Criterion library to measure code execution speed and performance consistency on aarch64 hardware.
11
+
This section demonstrates how to benchmark Rust performance using `cargo bench` and the Criterion library to measure code execution speed and performance consistency on Arm64 hardware.
12
12
13
-
###Create a benchmark project
13
+
## Create a benchmark project
14
14
15
15
Create a new Rust project specifically for benchmarking:
16
16
@@ -19,9 +19,9 @@ cargo new rust-benchmark
19
19
cd rust-benchmark
20
20
```
21
21
22
-
###Configure Criterion as a dependency
22
+
## Configure Criterion as a dependency
23
23
24
-
Criterion is the recommended benchmarking crate for Rust. Edit the `Cargo.toml` file in your project root directory and replace the existing content with:
24
+
Criterion is the recommended benchmarking crate for Rust. Open the `Cargo.toml` file in your project root directory and replace the existing content with:
25
25
26
26
```toml
27
27
[dependencies]
@@ -34,21 +34,15 @@ harness = false
34
34
35
35
This configuration enables Criterion for high-precision benchmarking and disables the default test harness.
36
36
37
-
###Create the benchmark directory and file
37
+
## Create the benchmark directory and file
38
38
39
39
Create the benchmark structure that Cargo expects:
40
40
41
41
```console
42
42
mkdir benches
43
43
```
44
44
45
-
Create a new benchmark file in the `benches/` directory:
46
-
47
-
```console
48
-
edit benches/my_benchmark.rs
49
-
```
50
-
51
-
Add the following benchmark code to measure Fibonacci number calculation performance:
45
+
Create a new file named `my_benchmark.rs` in the `benches/` directory and add the following benchmark code to measure Fibonacci number calculation performance:
This code implements a recursive Fibonacci function and measures how efficiently Rust computes the 20th Fibonacci number. The `black_box` function prevents the compiler from optimizing away the benchmark.
74
68
75
-
###Run the benchmark
69
+
## Run the benchmark
76
70
77
71
Execute the benchmark using Cargo:
78
72
@@ -92,29 +86,13 @@ Found 1 outliers among 100 measurements (1.00%)
92
86
1 (1.00%) low mild
93
87
```
94
88
95
-
### Benchmark Metrics Explanation
96
-
97
-
-**Average Time:** Mean execution time across benchmark runs.
98
-
-**Outliers:** Represent runs significantly slower or faster than average.
99
-
-**Plotting Backend:** Used `plotters` since Gnuplot was not found.
100
-
- The results show **consistent performance** with only slight variation across 100 measurements.
101
-
102
-
### Understand the results
103
-
104
-
The benchmark output provides several key metrics:
105
-
106
-
-**Average time**: Mean execution time across benchmark runs
107
-
-**Outliers**: Runs significantly slower or faster than average
108
-
-**Plotting backend**: Uses plotters since Gnuplot wasn't found
109
-
110
-
The results show consistent performance with only slight variation across 100 measurements.
111
-
112
-
### Performance summary
89
+
## Performance summary
90
+
The benchmark output provides several key metrics: the average time represents the mean execution time across benchmark runs, outliers identify runs that were significantly slower or faster than average, and the plotting backend indicates that plotters is being used since Gnuplot wasn't found on the system.
113
91
114
-
The following table shows results from running the benchmark on a `c4a-standard-4` (4 vCPU, 16 GB memory) aarch64 VM in GCP using SUSE:
92
+
The following table shows results from running the benchmark on a `c4a-standard-4` (4 vCPU, 16 GB memory) Arm64 VM in GCP using SUSE:
115
93
116
94
| Benchmark | Average Time (µs) | Min (µs) | Max (µs) | Outliers (%) | Remarks |
The Fibonacci benchmark demonstrates consistent performance on the aarch64 platform. The average execution time of 12.028 µs indicates efficient CPU computation, while only 1% of measurements were outliers. This low variance confirms Rust's reliable execution speed and performance stability on aarch64 architecture.
98
+
The Fibonacci benchmark demonstrates consistent performance on the Arm64 platform. The average execution time of 12.028 µs indicates efficient CPU computation, while only 1% of measurements were outliers. This low variance confirms Rust's reliable execution speed and performance stability on Arm64 architecture.
0 commit comments