Skip to content

Commit b9b7e95

Browse files
Refactor content for clarity and consistency in Profile-Guided Optimization documentation
1 parent 52232c6 commit b9b7e95

5 files changed

Lines changed: 27 additions & 13 deletions

File tree

content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ further_reading:
4343
link: https://learn.microsoft.com/en-us/windows/arm/overview
4444
type: documentation
4545
- resource:
46-
title: Arm Performance optimization resources
46+
title: Arm performance optimization resources
4747
link: https://learn.arm.com/learning-paths/laptops-and-desktops/
4848
type: website
4949

content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-1.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ First, you compile your program to produce an instrumented binary that collects
1414

1515
This approach identifies frequently executed paths (known as "hot" paths) and optimizes them more aggressively, while reducing emphasis on less critical code paths.
1616

17-
## How does PGO improve performance?
17+
## How PGO improves performance on Windows on Arm
1818

1919
PGO enables several compiler optimizations that aren't possible with static analysis alone.
2020

@@ -24,7 +24,7 @@ For C++ virtual functions, PGO can identify the most common call targets and opt
2424

2525
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.
2626

27-
## When should you use Profile-Guided Optimization?
27+
## When to use PGO on Arm
2828

2929
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.
3030

content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-2.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@ weight: 3
66
layout: learningpathall
77
---
88

9+
## Overview
10+
911
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.
1012

13+
## What is Google Benchmark?
14+
1115
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.
1216

1317
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.
1418

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
1620

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:
1824

1925
```cpp
2026
#include <benchmark/benchmark.h>
@@ -28,7 +34,7 @@ BENCHMARK(BM_StringCreation);
2834
BENCHMARK_MAIN();
2935
```
3036
31-
## Filter benchmarks and prevent compiler optimizations
37+
## Control benchmarks with Google Benchmark filters
3238
3339
Google Benchmark provides tools to ensure accurate measurements by preventing unintended compiler optimizations and allowing flexible benchmark selection.
3440
@@ -42,4 +48,6 @@ When you have multiple benchmarks, you can run a specific subset using the `--be
4248

4349
Filtering eliminates the need to repeatedly comment out lines of source code when you want to focus on specific benchmarks.
4450

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.

content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-3.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ weight: 4
66
layout: learningpathall
77
---
88

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.
1012

1113
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.
1214

1315
For this example, you'll use an Arm computer running Windows.
1416

15-
## Set up your environment
17+
## Set up Google Benchmark on Windows on Arm
1618

1719
Before you can run benchmarks, you need to install vcpkg (a C++ package manager) and Google Benchmark. This is a one-time setup step.
1820

@@ -56,7 +58,7 @@ BENCHMARK(baseDiv)->Arg(1500)->Unit(benchmark::kMicrosecond); // value of 1500 i
5658
BENCHMARK_MAIN();
5759
```
5860
59-
## Compile and run the baseline benchmark
61+
## Compile and run the baseline benchmark with MSVC
6062
6163
Open an **ARM64 Native Tools Command Prompt** from the Windows Start menu and start PowerShell:
6264
@@ -76,6 +78,8 @@ Compile the benchmark. This command uses the MSVC compiler and links with the Go
7678
cl /I"$VCPKG\include" /D BENCHMARK_STATIC_DEFINE div_bench.cpp /link /LIBPATH:"$VCPKG\lib" benchmark.lib benchmark_main.lib shlwapi.lib
7779
```
7880

81+
## Run the benchmark
82+
7983
Add the vcpkg binary directory to your PATH so the program can find required DLLs, then run the benchmark:
8084

8185
```console
@@ -86,7 +90,7 @@ $env:PATH += ";$HOME\pgo-benchmark\vcpkg_installed\arm64-windows\bin"
8690
The output is similar to:
8791

8892
```output
89-
Running ./div_bench.base
93+
Running ./div_bench.exe
9094
Run on (4 X 2100 MHz CPU s)
9195
CPU Caches:
9296
L1 Data 64 KiB (x4)
@@ -103,4 +107,6 @@ baseDiv/1500 7.90 us 7.90 us 88512
103107

104108
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.
105109

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.

content/learning-paths/laptops-and-desktops/win_profile_guided_optimisation/how-to-4.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ layout: learningpathall
88

99
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.
1010

11-
## Build the instrumented binary
11+
## Build instrumented binary with MSVC
1212

1313
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:
1414

0 commit comments

Comments
 (0)