gobject/performance: decrease warmup time and cleanups

Some tweakings of the time spend during warm up. That mostly matters if
you set very short "--seconds", which can make sense for quickly
checking something. Then the warmup should not take more thatn a certain
percentage of the requested runs.

When we have a constant factor, we still want not to run for more than
10% of the overall test time ... except, we still want to run at least
ESTIMATE_ROUND_TIME_N_RUNS (because we skip the estimation step below).

Also, adjust WARM_UP_ALWAYS_SEC to be only 20% of the test time, for
short test runs.

Also, don't print the messages about "Estimating round time" with a
fixed "--factor".
This commit is contained in:
Thomas Haller 2025-02-26 18:54:28 +01:00
parent fa66978cd5
commit b93108f07e

View File

@ -22,7 +22,6 @@
#include "../testcommon.h" #include "../testcommon.h"
#define WARM_UP_N_RUNS 50 #define WARM_UP_N_RUNS 50
#define WARM_UP_ALWAYS_SEC 2.0
#define ESTIMATE_ROUND_TIME_N_RUNS 5 #define ESTIMATE_ROUND_TIME_N_RUNS 5
#define DEFAULT_TEST_TIME 15 /* seconds */ #define DEFAULT_TEST_TIME 15 /* seconds */
/* The time we want each round to take, in seconds, this should /* The time we want each round to take, in seconds, this should
@ -81,6 +80,7 @@ run_test (PerformanceTest *test)
double var_mean = 0; double var_mean = 0;
double var_m2 = 0; double var_m2 = 0;
GTimer *timer; GTimer *timer;
const double WARM_UP_ALWAYS_SEC = MIN (2.0, test_length / 20);
if (verbose) if (verbose)
g_print ("Running test %s\n", test->name); g_print ("Running test %s\n", test->name);
@ -125,7 +125,11 @@ run_test (PerformanceTest *test)
if (i >= WARM_UP_N_RUNS) if (i >= WARM_UP_N_RUNS)
break; break;
if (test_factor == 0 && g_timer_elapsed (timer, NULL) > test_length / 10) if (test_factor > 0 && i < ESTIMATE_ROUND_TIME_N_RUNS)
{
/* run at least this many times with fixed factor. */
}
else if (g_timer_elapsed (timer, NULL) > test_length / 10)
{ {
/* The warm up should not take longer than 10 % of the entire /* The warm up should not take longer than 10 % of the entire
* test run. Note that the warm up time for WARM_UP_ALWAYS_SEC * test run. Note that the warm up time for WARM_UP_ALWAYS_SEC
@ -139,8 +143,7 @@ run_test (PerformanceTest *test)
if (verbose) if (verbose)
{ {
g_print ("Warm up time: %.2f secs\n", elapsed); g_print ("Warm up time: %.2f secs (%" G_GUINT64_FORMAT " rounds)\n", elapsed, i);
g_print ("Estimating round time\n");
} }
min_elapsed = 0; min_elapsed = 0;
@ -148,9 +151,13 @@ run_test (PerformanceTest *test)
if (test_factor > 0) if (test_factor > 0)
{ {
factor = test_factor; factor = test_factor;
if (verbose)
g_print ("Fixed correction factor %.2f\n", factor);
} }
else else
{ {
if (verbose)
g_print ("Estimating round time\n");
/* Estimate time for one run by doing a few test rounds. */ /* Estimate time for one run by doing a few test rounds. */
for (i = 0; i < ESTIMATE_ROUND_TIME_N_RUNS; i++) for (i = 0; i < ESTIMATE_ROUND_TIME_N_RUNS; i++)
{ {
@ -168,11 +175,10 @@ run_test (PerformanceTest *test)
} }
factor = TARGET_ROUND_TIME / min_elapsed; factor = TARGET_ROUND_TIME / min_elapsed;
if (verbose)
g_print ("Uncorrected round time: %.4f msecs, correction factor %.2f\n", 1000 * min_elapsed, factor);
} }
if (verbose)
g_print ("Uncorrected round time: %.4f msecs, correction factor %.2f\n", 1000*min_elapsed, factor);
/* Calculate number of rounds needed */ /* Calculate number of rounds needed */
num_rounds = (guint64) (test_length / TARGET_ROUND_TIME) + 1; num_rounds = (guint64) (test_length / TARGET_ROUND_TIME) + 1;