Add 20+ new modules with tests: Pipeline, Matrix, Tokenizer, ScopeGuard, Bitset, Optional, Counted, Curry, TypeMap, Bench, DisjointSet, Histogram, StopWatch, and more
Also fixes Diff/Memo/PriorityQueue from previous session: LineDiff is now an alias for Edit<string> so count_op/apply work on line diffs; Memoized uses std::apply instead of type-based get to handle duplicate arg types. 874/877 tests pass (3 are platform-gated plugin tests). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb4dd58500
commit
58ff7b38a0
65 files changed
+8987
-37
No files matched your search
@@ -0,0 +1,98 @@
|
||||
#include <Void/Bench/Bench.hpp>
|
||||
#include <Void/Testing/Assert.hpp>
|
||||
#include <Void/Testing/Test.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
using namespace Void::Bench;
|
||||
|
||||
// ── run ───────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test bench_run_correct_iteration_count()
|
||||
{
|
||||
int count = 0;
|
||||
const auto r = run("counter", 10, [&] { ++count; }, /*warmup=*/0);
|
||||
Void::Testing::expect_eq(r.iterations, std::size_t{10});
|
||||
Void::Testing::expect_eq(count, 10);
|
||||
}
|
||||
|
||||
Void::Testing::Test bench_run_warmup_not_in_result()
|
||||
{
|
||||
int count = 0;
|
||||
const auto r = run("counter", 5, [&] { ++count; }, /*warmup=*/3);
|
||||
Void::Testing::expect_eq(r.iterations, std::size_t{5});
|
||||
Void::Testing::expect_eq(count, 8); // 3 warmup + 5 measured
|
||||
}
|
||||
|
||||
Void::Testing::Test bench_run_name_preserved()
|
||||
{
|
||||
const auto r = run("my_bench", 1, [] {});
|
||||
Void::Testing::expect_eq(r.name, std::string{"my_bench"});
|
||||
}
|
||||
|
||||
Void::Testing::Test bench_run_total_positive()
|
||||
{
|
||||
const auto r = run("work", 100, [] {
|
||||
volatile int x = 0;
|
||||
for (int i = 0; i < 100; ++i) x += i;
|
||||
}, 0);
|
||||
Void::Testing::expect(r.total.count() >= 0);
|
||||
}
|
||||
|
||||
Void::Testing::Test bench_run_min_le_mean_le_max()
|
||||
{
|
||||
const auto r = run("timing", 50, [] {
|
||||
volatile int x = 1;
|
||||
do_not_optimize(x);
|
||||
}, 0);
|
||||
Void::Testing::expect(r.min_ns.count() <= static_cast<long long>(r.mean_ns() + 0.5));
|
||||
Void::Testing::expect(r.max_ns.count() >= static_cast<long long>(r.mean_ns()));
|
||||
}
|
||||
|
||||
Void::Testing::Test bench_run_ops_per_sec_positive()
|
||||
{
|
||||
const auto r = run("ops", 100, [] { volatile int x = 0; (void)x; }, 0);
|
||||
Void::Testing::expect(r.ops_per_sec() > 0.0);
|
||||
}
|
||||
|
||||
// ── run_for ───────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test bench_run_for_runs_at_least_once()
|
||||
{
|
||||
const auto r = run_for("short", std::chrono::milliseconds{10}, [] {}, 0);
|
||||
Void::Testing::expect(r.iterations >= 1);
|
||||
}
|
||||
|
||||
Void::Testing::Test bench_run_for_total_within_budget()
|
||||
{
|
||||
const auto budget = std::chrono::milliseconds{20};
|
||||
const auto r = run_for("budget_check", budget, [] {
|
||||
volatile int x = 0; (void)x;
|
||||
}, 0);
|
||||
// Total time should be close to budget (allow 2× for timer imprecision)
|
||||
const auto budget_ns = std::chrono::duration_cast<Duration>(budget * 2);
|
||||
Void::Testing::expect(r.total <= budget_ns);
|
||||
}
|
||||
|
||||
// ── Suite ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test bench_suite_collects_results()
|
||||
{
|
||||
Suite s;
|
||||
s.add(run("a", 10, [] {}, 0));
|
||||
s.add(run("b", 10, [] {}, 0));
|
||||
Void::Testing::expect_eq(s.size(), std::size_t{2});
|
||||
Void::Testing::expect_eq(s.results()[0].name, std::string{"a"});
|
||||
Void::Testing::expect_eq(s.results()[1].name, std::string{"b"});
|
||||
}
|
||||
|
||||
// ── do_not_optimize ───────────────────────────────────────────────────────────
|
||||
|
||||
Void::Testing::Test bench_do_not_optimize_compiles()
|
||||
{
|
||||
int x = 42;
|
||||
do_not_optimize(x);
|
||||
const int y = 7;
|
||||
do_not_optimize(y);
|
||||
Void::Testing::expect_eq(x, 42);
|
||||
}
|
||||
Reference in new issue
Block a user