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/laptops-and-desktops/win_profile_guided_optimisation/how-to-1.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ First, you compile your program to produce an instrumented binary that collects
14
14
15
15
This approach identifies frequently executed paths (known as "hot" paths) and optimizes them more aggressively, while reducing emphasis on less critical code paths.
16
16
17
-
## How does PGO improve performance?
17
+
## How PGO improves performance on Windows on Arm
18
18
19
19
PGO enables several compiler optimizations that aren't possible with static analysis alone.
20
20
@@ -24,7 +24,7 @@ For C++ virtual functions, PGO can identify the most common call targets and opt
24
24
25
25
If your application has an error handling path that rarely executes, PGO ensures the compiler doesn't optimize for that path at the expense of your main execution flow. Performance improvements typically range from 5-15%, though results vary by workload and architecture.
26
26
27
-
## When should you use Profile-Guided Optimization?
27
+
## When to use PGO on Arm
28
28
29
29
You'll find PGO particularly beneficial in the later stages of development when real-world workloads are available. It's especially useful for applications where performance is critical and runtime behavior is complex or data-dependent.
Copy file name to clipboardExpand all lines: content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-2.md
+12-4Lines changed: 12 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,15 +6,21 @@ weight: 3
6
6
layout: learningpathall
7
7
---
8
8
9
+
## Overview
10
+
9
11
Before you start working with Profile-Guided Optimization, you need to understand how to measure performance. This section introduces Google Benchmark, the tool you'll use to measure the impact of your optimizations. Don't worry about installing anything yet. You'll set up your environment and run your first benchmark in the next section.
10
12
13
+
## What is Google Benchmark?
14
+
11
15
Google Benchmark is a C++ library specifically designed for microbenchmarking, which means measuring the performance of small code snippets with high accuracy. Microbenchmarking helps you identify bottlenecks and optimize critical sections, especially in performance-sensitive applications.
12
16
13
17
Google Benchmark simplifies this process by providing a framework that manages iterations, times execution, and performs statistical analysis. You can focus on the code being measured, rather than writing test code or trying to prevent unwanted compiler optimizations manually.
14
18
15
-
To use Google Benchmark, you define a function that accepts a `benchmark::State&` parameter and iterate over it to perform the benchmarking. You register the function using the `BENCHMARK` macro and include `BENCHMARK_MAIN()` to generate the benchmark's entry point.
19
+
## Write a simple benchmark
16
20
17
-
The following example shows a basic benchmark that measures the time it takes to create an empty string:
21
+
To use Google Benchmark, define a function that accepts a benchmark::State& parameter and use it to run the benchmark in a loop. You register the function using the `BENCHMARK` macro and include `BENCHMARK_MAIN()` to generate the benchmark's entry point.
22
+
23
+
The following example shows a basic benchmark that measures the time it takes to create an empty string. A minimal benchmark looks like this:
18
24
19
25
```cpp
20
26
#include<benchmark/benchmark.h>
@@ -28,7 +34,7 @@ BENCHMARK(BM_StringCreation);
28
34
BENCHMARK_MAIN();
29
35
```
30
36
31
-
## Filter benchmarks and prevent compiler optimizations
37
+
## Control benchmarks with Google Benchmark filters
32
38
33
39
Google Benchmark provides tools to ensure accurate measurements by preventing unintended compiler optimizations and allowing flexible benchmark selection.
34
40
@@ -42,4 +48,6 @@ When you have multiple benchmarks, you can run a specific subset using the `--be
42
48
43
49
Filtering eliminates the need to repeatedly comment out lines of source code when you want to focus on specific benchmarks.
44
50
45
-
Now that you understand how Google Benchmark works, you're ready to install it and run your first benchmark. In the next section, you'll set up your environment and use Google Benchmark with Profile-Guided Optimization to measure and improve performance.
51
+
## What you've learned
52
+
53
+
You now understand how to write basic benchmarks with Google Benchmark, use `benchmark::DoNotOptimize` to prevent unwanted compiler optimizations, and filter benchmark execution with command-line options. In the next section, you'll install Google Benchmark and create a baseline benchmark to measure division performance on Windows on Arm.
Copy file name to clipboardExpand all lines: content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-3.md
+11-5Lines changed: 11 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,13 +6,15 @@ weight: 4
6
6
layout: learningpathall
7
7
---
8
8
9
-
In this section, you'll create a baseline benchmark to measure the performance of a division operation. This baseline will help you see the improvement when you apply Profile-Guided Optimization in the next section. This example demonstrates how even seemingly straightforward operations can benefit from optimization techniques.
9
+
## Overview
10
+
11
+
In this section, you'll create a baseline benchmark to measure the performance of a division operation. This baseline allows you to measure the improvement when you apply profile-guided optimization in the next section.
10
12
11
13
Integer division is ideal for benchmarking because it's significantly more expensive than operations like addition, subtraction, or multiplication. On most CPU architectures, including Arm, division instructions have higher latency and lower throughput compared to other arithmetic operations. By applying Profile-Guided Optimization to code containing division operations, you can achieve significant performance improvements.
12
14
13
15
For this example, you'll use an Arm computer running Windows.
14
16
15
-
## Set up your environment
17
+
## Set up Google Benchmark on Windows on Arm
16
18
17
19
Before you can run benchmarks, you need to install vcpkg (a C++ package manager) and Google Benchmark. This is a one-time setup step.
18
20
@@ -56,7 +58,7 @@ BENCHMARK(baseDiv)->Arg(1500)->Unit(benchmark::kMicrosecond); // value of 1500 i
56
58
BENCHMARK_MAIN();
57
59
```
58
60
59
-
## Compile and run the baseline benchmark
61
+
## Compile and run the baseline benchmark with MSVC
60
62
61
63
Open an **ARM64 Native Tools Command Prompt** from the Windows Start menu and start PowerShell:
62
64
@@ -76,6 +78,8 @@ Compile the benchmark. This command uses the MSVC compiler and links with the Go
@@ -103,4 +107,6 @@ baseDiv/1500 7.90 us 7.90 us 88512
103
107
104
108
The warning appears because the Google Benchmark library was built in debug mode, but it doesn't affect the validity of the measurements for this example.
105
109
106
-
The baseline shows an average execution time of 7.90 microseconds. This gives you a clear starting point to measure improvement. Now that you have this baseline measurement, you're ready to apply Profile-Guided Optimization. In the next section, you'll use PGO to optimize this code and see how much faster it can run.
110
+
## What you've accomplished
111
+
112
+
You've set up Google Benchmark on Windows on Arm, created a division-heavy benchmark, and established a baseline performance measurement of 7.90 microseconds. This baseline gives you a clear reference point to measure the impact of Profile-Guided Optimization. In the next section, you'll apply PGO to this code and measure the performance improvement.
Copy file name to clipboardExpand all lines: content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-4.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ layout: learningpathall
8
8
9
9
Now that you have a baseline benchmark, you're ready to apply Profile-Guided Optimization. The PGO process involves three steps: build an instrumented binary, run it to collect profile data, and rebuild with optimizations based on that data.
10
10
11
-
## Build the instrumented binary
11
+
## Build instrumented binary with MSVC
12
12
13
13
Open an **ARM64 Native Tools Command Prompt** from the Windows Start menu and start PowerShell if it's not already open. If you're starting a new session, navigate to your project directory and set the `$VCPKG` environment variable again:
0 commit comments