Debian Codegraph @

test/time.awk

raw
1 @load "time"
2
3 # make sure gettimeofday() is consistent with systime(). We must call
4 # gettimeofday() before systime() to make sure the subtraction gives 0
5 # without risk of rolling over to the next second.
6 function timecheck(st,res) {
7 res = gettimeofday()
8 st = systime()
9 printf "gettimeofday - systime = %d\n", res-st
10 return res
11 }
12
13 BEGIN {
14 delta = 1.3
15 t0 = timecheck()
16 printf "sleep(%s) = %s\n",delta,sleep(delta)
17 t1 = timecheck()
18 slept = t1-t0
19 if ((slept < 0.9*delta) || (slept > 1.3*delta))
20 printf "Warning: tried to sleep %.2f secs, but slept for %.2f secs\n",
21 delta,slept
22
23 format = "%b %d %H:%M:%S %Y"
24 the_date = "Feb 11 13:12:11 1990"
25 then = strptime(the_date, format)
26 when = strftime(format, then)
27 print "<" the_date ">", "<<" when ">>"
28 }