File: time.awk

package info (click to toggle)
gawk 1%3A4.1.4%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 16,836 kB
  • ctags: 5,783
  • sloc: ansic: 48,799; awk: 11,167; yacc: 5,939; sh: 5,579; makefile: 2,554; sed: 121
file content (22 lines) | stat: -rw-r--r-- 621 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
@load "time"

# make sure gettimeofday() is consistent with systime().  We must call
# gettimeofday() before systime() to make sure the subtraction gives 0
# without risk of rolling over to the next second.
function timecheck(st,res) {
   res = gettimeofday()
   st = systime()
   printf "gettimeofday - systime = %d\n", res-st
   return res
}

BEGIN {
   delta = 1.3
   t0 = timecheck()
   printf "sleep(%s) = %s\n",delta,sleep(delta)
   t1 = timecheck()
   slept = t1-t0
   if ((slept < 0.9*delta) || (slept > 1.3*delta))
      printf "Warning: tried to sleep %.2f secs, but slept for %.2f secs\n",
	     delta,slept
}