+linux.ha (607B)
1 // License: MPL-2.0 2 // (c) 2021 Drew DeVault <sir@cmpwn.com> 3 // (c) 2021 Ember Sawady <ecs@d2evs.net> 4 5 let start: timespec = timespec { ... }; 6 7 fn time_start() void = { 8 clock_gettime(CLOCK_MONOTONIC, &start) as void; 9 }; 10 11 // Returns elapsed time as (seconds, milliseconds) 12 fn time_stop() (size, size) = { 13 let end: timespec = timespec { ... }; 14 clock_gettime(CLOCK_MONOTONIC, &end) as void; 15 let sec_diff = end.tv_sec - start.tv_sec; 16 let nsec_diff = end.tv_nsec - start.tv_nsec; 17 if (nsec_diff < 0) { 18 nsec_diff += 1000000000; 19 sec_diff -= 1; 20 }; 21 return (sec_diff: size, nsec_diff: size / 1000000z); 22 };