Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
---
Since v1: no changes.
rt/+test/+freebsd.ha | 9 +++++++--
rt/+test/+linux.ha | 9 +++++++--
2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/rt/+test/+freebsd.ha b/rt/+test/+freebsd.ha
index e815bea2..6d31844a 100644
--- a/rt/+test/+freebsd.ha
+++ b/rt/+test/+freebsd.ha
@@ -11,6 +11,11 @@ fn time_start() void = {
fn time_stop() (size, size) = {
let end: timespec = timespec { ... };
clock_gettime(CLOCK_MONOTONIC, &end) as void;
- return ((end.tv_sec - start.tv_sec): size,
- (end.tv_nsec - start.tv_nsec): size / 10000z);
+ let sec_diff = end.tv_sec - start.tv_sec;
+ let nsec_diff = end.tv_nsec - start.tv_nsec;
+ if (nsec_diff < 0) {
+ nsec_diff += 1000000000;
+ sec_diff -= 1;
+ };
+ return (sec_diff: size, nsec_diff: size / 1000000z);
};
diff --git a/rt/+test/+linux.ha b/rt/+test/+linux.ha
index 89b0fe41..ff5c2424 100644
--- a/rt/+test/+linux.ha
+++ b/rt/+test/+linux.ha
@@ -12,6 +12,11 @@ fn time_start() void = {
fn time_stop() (size, size) = {
let end: timespec = timespec { ... };
clock_gettime(CLOCK_MONOTONIC, &end) as void;
- return ((end.tv_sec - start.tv_sec): size,
- (end.tv_nsec - start.tv_nsec): size / 10000z);
+ let sec_diff = end.tv_sec - start.tv_sec;
+ let nsec_diff = end.tv_nsec - start.tv_nsec;
+ if (nsec_diff < 0) {
+ nsec_diff += 1000000000;
+ sec_diff -= 1;
+ };
+ return (sec_diff: size, nsec_diff: size / 1000000z);
};
--
2.38.1
Pad milliseconds with zeroes; the number is guaranteed to be in [0, 999]
range so these two checks are enough.
Signed-off-by: Kirill Primak <vyivel@eclair.cafe>
---
Since v1: reformatted the code.
rt/+test/run.ha | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/rt/+test/run.ha b/rt/+test/run.ha
index 7e0635ea..a86ea7da 100644
--- a/rt/+test/run.ha
+++ b/rt/+test/run.ha
@@ -89,6 +89,11 @@ export fn tests_main() size = {
print(" tests completed in ");
print(ztos(end.0));
print(".");
+ if (end.1 < 10) {
+ print("00");
+ } else if (end.1 < 100) {
+ print("0");
+ };
print(ztos(end.1));
print("s\n");
--
2.38.1