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")
5 if has_syscall and syscall.clock_gettime and syscall.c.CLOCK then
6 local clock_id = syscall.c.CLOCK.REALTIME
7 local function timespec_to_number(timespec)
8 return tonumber(timespec.tv_sec) + tonumber(timespec.tv_nsec) * 1e-9
10 return "syscall.clock_gettime(CLOCK_REALTIME)",
11 syscall.clock_getres and timespec_to_number(syscall.clock_getres(clock_id)) or 1e-9,
13 return timespec_to_number(syscall.clock_gettime(clock_id))
17 local has_unix, unix = pcall(require, "unix")
18 -- On Apple devices lunix only uses gettimeofday()
19 if has_unix and unix.clock_gettime and unix.uname and unix.uname().sysname ~= "Darwin" then
20 return "unix.clock_gettime(CLOCK_REALTIME)", 1e-9, function()
21 return unix.clock_gettime()
25 if has_syscall and syscall.gettimeofday then
26 local function timeval_to_number(timeval)
27 return tonumber(timeval.tv_sec) + tonumber(timeval.tv_nsec) * 1e-6
29 return "syscall.gettimeofday()", 1e-6,
31 return timeval_to_number(syscall.gettimeofday())
35 if has_unix and unix.gettimeofday then
36 return "unix.gettimeofday()", 1e-6, unix.gettimeofday
39 local has_socket, socket = pcall(require, "socket")
40 if has_socket and socket.gettime then
41 -- on windows, this uses GetSystemTimeAsFileTime, which has resolution of 1e-7
42 -- on linux, this uses gettimeofday, which has resolution of 1e-6
43 return "socket.gettime()", 1e-6, socket.gettime
46 if ngx and ngx.now then -- luacheck: ignore 113
47 return "ngx.now()", 1e-3, ngx.now -- luacheck: ignore 113
50 return "os.time()", 1, os.time