[PATCH v2 2/4] time: test: Avoid unnecessary divisions in time64_to_tm() test

From: Thomas Weißschuh (Schneider Electric)

Date: Mon Nov 23 2026 - 03:11:54 EST


The time64_to_tm_test_date_range() test case is slow.
One big part of this slowness is the division done in the test loop to
calculate the current day from the current seconds. As each test loop
advances the time by one day, that division can be avoided.

Remove the division and instead increment the 'days' variable directly.

This brings the test's runtime from 30 seconds down to 15 seconds in an
emulated 32-bit ARM machine.

Signed-off-by: Thomas Weißschuh (Schneider Electric) <thomas.weissschuh@xxxxxxxxxxxxx>
---
kernel/time/time_test.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/time/time_test.c b/kernel/time/time_test.c
index 8b718767b3ba..41e504aa2883 100644
--- a/kernel/time/time_test.c
+++ b/kernel/time/time_test.c
@@ -69,12 +69,12 @@ static void time64_to_tm_test_date_range(struct kunit *test)
time64_t secs;
s64 days;

- for (secs = -total_secs; secs <= total_secs; secs += 86400) {
+ for (secs = -total_secs, days = div_s64(secs, 86400);
+ secs <= total_secs;
+ secs += 86400, days++) {

time64_to_tm(secs, 0, &result);

- days = div_s64(secs, 86400);
-
#define FAIL_MSG "%05ld/%02d/%02d (%2d) : %lld", \
year, month, mdday, yday, days


--
2.56.1