Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
99 lines
3.5 KiB
C++
99 lines
3.5 KiB
C++
#include <Void/Time/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);
|
||
}
|