Skip to content

Commit c66e461

Browse files
committed
clean up on benchmarking and yaml
1 parent 008bb9b commit c66e461

File tree

2 files changed

+6
-46
lines changed

2 files changed

+6
-46
lines changed

docs/google_benchmark.md

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
1-
Google Benchmark is a micro-benchmarking library developed by Google that helps you measure the performance of individual code snippets or small parts of a program. It is particularly useful for performance-critical code where you need to optimize specific functions or algorithms.
2-
3-
### Key Features of Google Benchmark:
4-
1. **Simple API**: The library provides an easy-to-use API for defining and running benchmarks.
5-
2. **Automatic Iteration Count**: It automatically determines the number of iterations required to get an accurate measurement.
6-
3. **Customizable**: You can customize benchmarks by specifying the number of iterations, setting up custom counters, or adding user-defined options.
7-
4. **Reporting and Output**: The library provides detailed output of the benchmarking results, including mean, median, and standard deviation.
8-
9-
### How to Use Google Benchmark
10-
11-
Let's walk through a simple example to understand how Google Benchmark works.
1+
## Google Benchmark
2+
Google Benchmark is a micro-benchmarking library developed by Google that helps you measure the performance of individual code snippets or small parts of a program. It is particularly useful for performance-critical code where you need to optimize specific functions or algorithms. It automatically determines the number of iterations required to get an accurate measurement. The library provides detailed output of the benchmarking results, including mean, median, and standard deviation.
123

134
### Example 1: Benchmarking a Simple Function
145

@@ -112,25 +103,7 @@ void BM_Throughput(benchmark::State& state) {
112103
BENCHMARK(BM_Throughput);
113104
114105
BENCHMARK_MAIN();
115-
```
116106
117-
**Explanation**:
118-
- `benchmark::DoNotOptimize(some_operation());` ensures that the compiler does not optimize away the operation being benchmarked.
119-
- `state.SetItemsProcessed(state.iterations());` reports the number of items processed, which can be used to calculate throughput.
120-
121-
### Running the Benchmarks
122-
To compile and run these benchmarks, you would typically do the following:
123-
124-
1. **Compile** the program using a C++ compiler, ensuring that you link against the Google Benchmark library.
125-
2. **Run** the resulting executable, which will automatically execute the benchmarks and output the results.
126-
127-
```bash
128-
$ g++ -std=c++11 benchmark_example.cpp -lbenchmark -lpthread -o benchmark_example
129-
$ ./benchmark_example
130107
```
108+
[code](../src/benchmark_demo.cpp)
131109

132-
### Output
133-
The output will include the function name, the number of iterations, the time taken per iteration, and other statistics.
134-
135-
### Summary
136-
Google Benchmark is a powerful tool for performance testing in C++. By writing simple benchmark functions and registering them, you can measure the performance of specific code paths in your application, enabling more informed decisions about optimizations.

docs/yaml-cpp.md

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
`yaml-cpp` is a popular C++ library for parsing and emitting YAML. Below is an example that demonstrates how to use `yaml-cpp` to parse a YAML file and access its contents.
2-
31
### YAML Example File
42

53
Let's assume we have a YAML file named `example.yaml` with the following content:
@@ -62,21 +60,7 @@ int main() {
6260
}
6361
```
6462

65-
### Explanation
66-
67-
- **Loading the YAML file**: `YAML::LoadFile("example.yaml")` reads the YAML file and creates a `YAML::Node` object.
68-
- **Accessing data**: The `YAML::Node` object provides methods like `as<std::string>()` to convert YAML nodes to the desired C++ type.
69-
- **Iterating over sequences**: If the YAML node represents a sequence (like the `phones` array), you can iterate over it using a loop.
70-
71-
### Compilation
72-
73-
To compile the above code, you'll need to link the `yaml-cpp` library. Here’s an example command using `g++`:
7463

75-
```bash
76-
g++ -o yaml_example yaml_example.cpp -lyaml-cpp
77-
```
78-
79-
### Output
8064

8165
When you run the compiled program, it will print the contents of the YAML file:
8266

@@ -87,3 +71,6 @@ Name: John Doe
8771
Age: 30
8872
Address: 123 Maple Street, Springfield, IL
8973
```
74+
75+
76+
[code](../src/yaml-cpp_example.cpp)

0 commit comments

Comments
 (0)