From cb6821bbbb191868a7b6c8813f8481c897d9dba9 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 18 Feb 2015 16:15:22 -0500 Subject: [PATCH] {luatz,doc}/gettime: Add Openresty's ngx.now as a source nginx has it's own gettimeofday() cache, this will fetch the time from there. It has only in millisecond granularity, so place it after luasocket in preferential order As requested by bngle --- doc/gettime.md | 1 + luatz/gettime.lua | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/doc/gettime.md b/doc/gettime.md index faabfb4..0457855 100644 --- a/doc/gettime.md +++ b/doc/gettime.md @@ -8,6 +8,7 @@ Uses the most precise method available (in order:) - `clock_gettime(2)` called with `CLOCK_REALTIME` - `gettimeofday(2)` - [luasocket](http://w3.impa.br/~diego/software/luasocket/)'s `socket.gettime` + - [Openresty](http://openresty.org/)'s [`ngx.now`](http://wiki.nginx.org/HttpLuaModule#ngx.now) - [`os.time`](http://www.lua.org/manual/5.2/manual.html#pdf-os.time) ### `source` diff --git a/luatz/gettime.lua b/luatz/gettime.lua index 008e95c..65366bd 100644 --- a/luatz/gettime.lua +++ b/luatz/gettime.lua @@ -32,6 +32,10 @@ _M.source , _M.resolution , _M.gettime = (function() return "socket.gettime()" , 1e-6 , socket.gettime end + if ngx and ngx.now then + return "ngx.now()" , 1e-3 , ngx.now + end + return "os.time()" , 1 , os.time end)() -- 2.39.5