All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 _M.source , _M.resolution , _M.gettime = (function()
4 local has_syscall , syscall = pcall ( require , "syscall" )
6 if syscall.clock_gettime then
7 local clock_id = syscall.c.CLOCK.REALTIME
8 local function timespec_to_number ( timespec )
9 return tonumber ( timespec.tv_sec ) + tonumber ( timespec.tv_nsec ) * 1e-9
11 return "syscall.clock_gettime(CLOCK_REALTIME)" ,
12 syscall.clock_getres and timespec_to_number ( syscall.clock_getres ( clock_id ) ) or 1e-9 ,
14 return timespec_to_number ( syscall.clock_gettime ( clock_id ) )
17 elseif syscall.gettimeofday then
18 local function timeval_to_number ( timeval )
19 return tonumber ( timeval.tv_sec ) + tonumber ( timeval.tv_nsec ) * 1e-6
21 return "syscall.gettimeofday()" , 1e-6 ,
23 return timeval_to_number ( syscall.gettimeofday ( ) )
28 local has_socket , socket = pcall ( require , "socket" )
29 if has_socket and socket.gettime then
30 -- on windows, this uses GetSystemTimeAsFileTime, which has resolution of 1e-7
31 -- on linux, this uses gettimeofday, which has resolution of 1e-6
32 return "socket.gettime()" , 1e-6 , socket.gettime
35 if ngx and ngx.now then -- luacheck: ignore 113
36 return "ngx.now()" , 1e-3 , ngx.now -- luacheck: ignore 113
39 return "os.time()" , 1 , os.time