centralized performance resources

This commit is contained in:
Barrett Ruth 2026-01-10 12:21:52 -05:00
commit 50b15a1522
63 changed files with 328466 additions and 0 deletions

BIN
ocw/profiling/a.out Executable file

Binary file not shown.

File diff suppressed because it is too large Load diff

89225
ocw/profiling/demangled.s Normal file

File diff suppressed because it is too large Load diff

39
ocw/profiling/notes.md Normal file
View file

@ -0,0 +1,39 @@
# profiling
## intro
### instrumentation: overall timing (usual idea)
- while timing a clock with `time_the_clock.cc`, i erroneously initialized a
`chrono::microseconds` default. this can be seen in the STL source: the default constructor
initializes the `Rep` (repeated value, the unit for the duration) by
default. A `microsecond` is a long here - this became garbage.
- NOTE: timing the clock (with 0 optimization) took ~0ns and is not of significance for my profiling. I concluded this by compiling with `-O0` and de-mangling with c++filt we can see this is the case: we can see this is the case and nothing is being optimized out:
```asm
.L585:
call std::chrono::_V2::system_clock::now()@PLT
movq %rax, -64(%rbp)
call std::chrono::_V2::system_clock::now()@PLT
```
However, I acknowledge that this code is not run one-for-one. I don't have the
knowledge to assess caching done by the actual CPU itself, or even other side
effects like inlining.
So far, though, one lesson of profiling is:
> Only profile the code *actually* being profiled
### statistical profiling
- more accurate by *experimental* virtue - probabilistic look
- imagine the execution of the program as a "strip" of time
- system-specific, but so was before
- statistical: stats
- program simulation: ll
## exercise 1
- use cachegrind/valgrind/asan on cf problem
- apply bentley's rules to some code
- begin developing a strategy for how to profile things

26698
ocw/profiling/output.svg Normal file

File diff suppressed because it is too large Load diff

After

Width:  |  Height:  |  Size: 1.2 MiB

BIN
ocw/profiling/perf-tester Executable file

Binary file not shown.

View file

@ -0,0 +1,19 @@
#include <iostream>
void complex_method() {
int i = 0x12323333- 1230*123213;
long x = -23;
std::cout << "x: " << x << '\n';
while (--i) {
x ^= (x - 1);
for (int j = 0; j < 50; ++j) {
x = x * x * x;
}
}
}
int main() {
complex_method();
return 0;
}

BIN
ocw/profiling/perf.data Normal file

Binary file not shown.

BIN
ocw/profiling/perf.data.old Normal file

Binary file not shown.

114179
ocw/profiling/perf.script Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,24 @@
#include <chrono>
#include <iostream>
#include <print>
using namespace std;
constexpr static size_t TRIALS = 100000;
int main() {
chrono::microseconds diffs_ms{0};
for (size_t loop_var = 1; loop_var <= TRIALS; ++loop_var) {
auto t1 = chrono::high_resolution_clock::now();
auto t2 = chrono::high_resolution_clock::now();
diffs_ms += chrono::duration_cast<chrono::microseconds>(t2 - t1);
}
print("measuring the clock in c++ 23 {} trials had an average time duration "
"of: {} microseconds, or {} milliseconds",
TRIALS, diffs_ms / TRIALS,
chrono::duration_cast<chrono::milliseconds>(diffs_ms / TRIALS));
return 0;
}

89225
ocw/profiling/time_the_clock.s Normal file

File diff suppressed because it is too large Load diff