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/memory_demo.cpp | |
| parent | 9023d106c61db0be0de6460a397bbad42bbc3d96 (diff) | |
refactor: reorganize tests
Diffstat (limited to 'test/memory_demo.cpp')
| -rw-r--r-- | test/memory_demo.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/memory_demo.cpp b/test/memory_demo.cpp new file mode 100644 index 0000000..22c6b44 --- /dev/null +++ b/test/memory_demo.cpp @@ -0,0 +1,31 @@ +// a small demo target for the profiler: allocates and frees memory in slow +// waves so the resident-memory graph has something to show +#include <chrono> +#include <cstdio> +#include <thread> +#include <vector> + +auto main() -> int +{ + std::vector<std::vector<char>> blocks; + + for (int cycle = 0; cycle < 6; ++cycle) + { + // ramp up: grab ~40 MB over two seconds + for (int i = 0; i < 40; ++i) + { + blocks.emplace_back(1024 * 1024, static_cast<char>(i)); + std::printf("cycle %d: allocated %zu MB\n", cycle, blocks.size()); + std::fflush(stdout); + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + } + + // hold for a moment, then release everything and start over + std::this_thread::sleep_for(std::chrono::seconds(1)); + blocks.clear(); + blocks.shrink_to_fit(); + std::this_thread::sleep_for(std::chrono::seconds(1)); + } + + std::puts("done"); +} |
