1 The `clock()` function reads the current second and microsecond value of 2 the system clock, optionally using the monotonic clock instead of the 3 default realtime one. 4 5 -- Testcase -- 6 {% 7 let t1 = clock(); 8 let t3 = clock(true); 9 10 sleep(250); 11 12 let t2 = clock(); 13 let t4 = clock(true); 14 15 let delta1 = (t2[0] - t1[0]) * 1000000000 + (t2[1] - t1[1]); 16 let delta2 = (t4[0] - t3[0]) * 1000000000 + (t4[1] - t3[1]); 17 18 assert(delta1 >= 0, "Realtime clock went backwards!"); 19 assert(delta2 >= 0, "Monotonic clock went backwards!"); 20 21 printf("%.J\n", [ 22 (delta1 >= 240000000 && delta1 <= 260000000) ? true : "unexpected delta: " + delta1, 23 (delta2 >= 240000000 && delta2 <= 260000000) ? true : "unexpected delta: " + delta2 24 ]); 25 %} 26 -- End -- 27 28 -- Expect stdout -- 29 [ 30 true, 31 true 32 ] 33 -- End --
This page was automatically generated by LXR 0.3.1. • OpenWrt