Files
OrcaSlicer/tests/slic3rutils/test_scene_benchmark.cpp
T
Hanif Koh 0a30cfe6b0 Remove Unused Project Includes and Forward-Declare Where a Type Is Only Referenced
Generated with include-what-you-use and applied conservatively. Only OrcaSlicer's own headers, the ones under src/ and tests/, are removed or forward-declared; standard-library and third-party includes are left alone. An include is removed only when both the Release and the Debug configuration leave it unused, never from inside a conditional block, and never from a file with platform-specific blocks, which only gain includes. Files whose only use of a header sits behind a feature or debug macro (libvgcode's OpenGL ES and marker code, the ARACHNE/TESTS_EXPORT_SVGS debug output) keep their includes.

clonable_ptr.hpp gains #pragma once; it had no include guard and was only safe while Config.hpp was its sole includer.
2026-10-03 22:45:55 +08:00

61 lines
2.2 KiB
C++

#include <catch2/catch_all.hpp>
#include "slic3r/GUI/SceneBenchmark.hpp"
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
using Catch::Matchers::WithinAbs;
using Slic3r::GUI::frame_time_stats;
using Slic3r::GUI::FrameTimeStats;
TEST_CASE("Frame time statistics take percentiles by nearest rank", "[SceneBenchmark]")
{
// 1 to 100 ms in shuffled order: the p-th percentile is the p-th frame time.
std::vector<double> frame_ms(100);
std::iota(frame_ms.begin(), frame_ms.end(), 1.0);
std::shuffle(frame_ms.begin(), frame_ms.end(), std::mt19937(42));
const FrameTimeStats stats = frame_time_stats(frame_ms);
CHECK_THAT(stats.average_ms, WithinAbs(50.5, 1e-9));
CHECK_THAT(stats.fps, WithinAbs(1000.0 / 50.5, 1e-9));
CHECK_THAT(stats.median_ms, WithinAbs(50.0, 1e-9));
CHECK_THAT(stats.p95_ms, WithinAbs(95.0, 1e-9));
CHECK_THAT(stats.p99_ms, WithinAbs(99.0, 1e-9));
CHECK_THAT(stats.max_ms, WithinAbs(100.0, 1e-9));
}
TEST_CASE("Frame time percentiles are measured frame times", "[SceneBenchmark]")
{
// 360 frames, as in a benchmark pass: rank 342 for p95 and rank 357 for p99.
std::vector<double> frame_ms(360);
std::iota(frame_ms.begin(), frame_ms.end(), 1.0);
const FrameTimeStats stats = frame_time_stats(frame_ms);
CHECK_THAT(stats.median_ms, WithinAbs(180.0, 1e-9));
CHECK_THAT(stats.p95_ms, WithinAbs(342.0, 1e-9));
CHECK_THAT(stats.p99_ms, WithinAbs(357.0, 1e-9));
}
TEST_CASE("Frame time statistics of a single frame are that frame", "[SceneBenchmark]")
{
const FrameTimeStats stats = frame_time_stats({ 4.0 });
CHECK_THAT(stats.fps, WithinAbs(250.0, 1e-9));
CHECK_THAT(stats.median_ms, WithinAbs(4.0, 1e-9));
CHECK_THAT(stats.p99_ms, WithinAbs(4.0, 1e-9));
CHECK_THAT(stats.max_ms, WithinAbs(4.0, 1e-9));
}
TEST_CASE("Frame time statistics of no frames are zero", "[SceneBenchmark]")
{
const FrameTimeStats stats = frame_time_stats({});
CHECK_THAT(stats.fps, WithinAbs(0.0, 1e-9));
CHECK_THAT(stats.average_ms, WithinAbs(0.0, 1e-9));
CHECK_THAT(stats.max_ms, WithinAbs(0.0, 1e-9));
}