diff options
| author | hachem <im@hachem.wtf> | 2026-09-04 05:46:36 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-09-04 05:46:36 +0200 |
| commit | d3a1b908fd3b0c47da2c33c16d18ebeb00da3b97 (patch) | |
| tree | 1e8861de97ebd0c580a0cfaa4c759cf3e5be8e3b /test/sample_demo.cpp | |
| parent | 9023d106c61db0be0de6460a397bbad42bbc3d96 (diff) | |
refactor: reorganize tests
Diffstat (limited to 'test/sample_demo.cpp')
| -rw-r--r-- | test/sample_demo.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/sample_demo.cpp b/test/sample_demo.cpp new file mode 100644 index 0000000..a3b1fa8 --- /dev/null +++ b/test/sample_demo.cpp @@ -0,0 +1,47 @@ +// a plain, un-instrumented target for the sampling profiler: NOTHING added to the +// build, no flags, no linked runtime. functions do enough work (tens of ms) that +// the sampler catches them. compile normally: clang++ -g sample_demo.cpp -o sample_demo +#include <cstdio> + +// a spin of roughly the requested milliseconds of busywork +static volatile long sink = 0; +static void burn(int ms) +{ + // ~2 million iterations per ms is a rough guess; exact timing does not matter + for (long i = 0; i < ms * 800000L; ++i) + sink += i % 7; +} + +static void deep(int round) +{ + burn(25 + round % 3 * 15); +} + +static void phase_b(int round) +{ + burn(20); + deep(round); +} + +static void phase_a(int round) +{ + burn(40); +} + +int main() +{ + for (int round = 0; round < 400; ++round) + { + phase_a(round); + phase_b(round); + + if (round % 10 == 0) + { + printf("round %d\n", round); + fflush(stdout); + } + } + + puts("done"); + return 0; +} |
