diff options
| author | hachem <im@hachem.wtf> | 2025-12-21 05:46:36 +0100 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-12-21 05:46:36 +0100 |
| commit | d660dc5748656e7ddc7b3343c96d9a7bdaadd502 (patch) | |
| tree | 1b68729fdb8a5f2d0db62b6eabac90b76efba4d8 /test/sample_demo.cpp | |
| parent | 15b4b64475138a810d4c4dde485c08603ceb592a (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; +} |
