mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibTest: Ensure other
time statistic doesn't underflow
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, Linux-x86_64) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This commit is contained in:
parent
9dbeecb73d
commit
23cdd78f1a
Notes:
github-actions[bot]
2025-04-10 09:18:06 +00:00
Author: https://github.com/ttrssreal
Commit: 23cdd78f1a
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3632
Reviewed-by: https://github.com/ADKaster
Reviewed-by: https://github.com/gmta ✅
2 changed files with 30 additions and 19 deletions
|
@ -25,9 +25,9 @@ public:
|
|||
|
||||
void restart() { m_started = UnixDateTime::now(); }
|
||||
|
||||
u64 elapsed_milliseconds()
|
||||
AK::Duration elapsed() const
|
||||
{
|
||||
return (UnixDateTime::now() - m_started).to_milliseconds();
|
||||
return UnixDateTime::now() - m_started;
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -187,17 +187,18 @@ int TestSuite::run(Vector<NonnullRefPtr<TestCase>> const& tests)
|
|||
m_current_test_result = TestResult::NotRun;
|
||||
enable_reporting();
|
||||
|
||||
u64 total_time = 0;
|
||||
AK::Duration total_time;
|
||||
u64 sum_of_squared_times = 0;
|
||||
u64 min_time = NumericLimits<u64>::max();
|
||||
u64 max_time = 0;
|
||||
AK::Duration min_time = AK::Duration::max();
|
||||
AK::Duration max_time;
|
||||
|
||||
for (u64 i = 0; i < repetitions; ++i) {
|
||||
TestElapsedTimer timer;
|
||||
t->func()();
|
||||
auto const iteration_time = timer.elapsed_milliseconds();
|
||||
auto const iteration_time = timer.elapsed();
|
||||
auto const iteration_ms = iteration_time.to_milliseconds();
|
||||
total_time += iteration_time;
|
||||
sum_of_squared_times += iteration_time * iteration_time;
|
||||
sum_of_squared_times += iteration_ms * iteration_ms;
|
||||
min_time = min(min_time, iteration_time);
|
||||
max_time = max(max_time, iteration_time);
|
||||
|
||||
|
@ -206,20 +207,26 @@ int TestSuite::run(Vector<NonnullRefPtr<TestCase>> const& tests)
|
|||
m_current_test_result = TestResult::Passed;
|
||||
}
|
||||
|
||||
auto const total_time_ms = total_time.to_milliseconds();
|
||||
|
||||
if (repetitions != 1) {
|
||||
double average = total_time / double(repetitions);
|
||||
double average = total_time_ms / static_cast<double>(repetitions);
|
||||
double average_squared = average * average;
|
||||
double standard_deviation = sqrt((sum_of_squared_times + repetitions * average_squared - 2 * total_time * average) / (repetitions - 1));
|
||||
double standard_deviation = sqrt((sum_of_squared_times + repetitions * average_squared - 2 * total_time_ms * average) / (repetitions - 1));
|
||||
|
||||
dbgln("{} {} '{}' on average in {:.1f}±{:.1f}ms (min={}ms, max={}ms, total={}ms)",
|
||||
test_result_to_string(m_current_test_result), test_type, t->name(),
|
||||
average, standard_deviation, min_time, max_time, total_time);
|
||||
average,
|
||||
standard_deviation,
|
||||
min_time.to_milliseconds(),
|
||||
max_time.to_milliseconds(),
|
||||
total_time_ms);
|
||||
} else {
|
||||
dbgln("{} {} '{}' in {}ms", test_result_to_string(m_current_test_result), test_type, t->name(), total_time);
|
||||
dbgln("{} {} '{}' in {}ms", test_result_to_string(m_current_test_result), test_type, t->name(), total_time_ms);
|
||||
}
|
||||
|
||||
if (t->is_benchmark()) {
|
||||
m_benchtime += total_time;
|
||||
m_bench_time += total_time;
|
||||
benchmark_count++;
|
||||
|
||||
switch (m_current_test_result) {
|
||||
|
@ -233,7 +240,7 @@ int TestSuite::run(Vector<NonnullRefPtr<TestCase>> const& tests)
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
m_testtime += total_time;
|
||||
m_test_time += total_time;
|
||||
test_count++;
|
||||
|
||||
switch (m_current_test_result) {
|
||||
|
@ -249,13 +256,16 @@ int TestSuite::run(Vector<NonnullRefPtr<TestCase>> const& tests)
|
|||
}
|
||||
}
|
||||
|
||||
auto const runtime = m_test_time + m_bench_time;
|
||||
auto const elapsed = global_timer.elapsed() - runtime;
|
||||
|
||||
dbgln("Finished {} tests and {} benchmarks in {}ms ({}ms tests, {}ms benchmarks, {}ms other).",
|
||||
test_count,
|
||||
benchmark_count,
|
||||
global_timer.elapsed_milliseconds(),
|
||||
m_testtime,
|
||||
m_benchtime,
|
||||
global_timer.elapsed_milliseconds() - (m_testtime + m_benchtime));
|
||||
elapsed.to_truncated_milliseconds(),
|
||||
m_test_time.to_truncated_milliseconds(),
|
||||
m_bench_time.to_truncated_milliseconds(),
|
||||
(elapsed - runtime).to_truncated_milliseconds());
|
||||
|
||||
if (test_count != 0) {
|
||||
if (test_passed_count == test_count) {
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include <AK/ByteString.h>
|
||||
#include <AK/Function.h>
|
||||
#include <AK/Time.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibTest/Macros.h>
|
||||
#include <LibTest/Randomized/RandomnessSource.h>
|
||||
|
@ -65,8 +66,8 @@ public:
|
|||
private:
|
||||
static TestSuite* s_global;
|
||||
Vector<NonnullRefPtr<TestCase>> m_cases;
|
||||
u64 m_testtime = 0;
|
||||
u64 m_benchtime = 0;
|
||||
AK::Duration m_test_time;
|
||||
AK::Duration m_bench_time;
|
||||
ByteString m_suite_name;
|
||||
u64 m_benchmark_repetitions = 1;
|
||||
u64 m_randomized_runs = 100;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue