From: daurnimator Date: Wed, 18 Feb 2015 21:15:22 +0000 (-0500) Subject: {luatz,doc}/gettime: Add Openresty's ngx.now as a source X-Git-Url: https://git.madduck.net/etc/awesome.git/commitdiff_plain/cb6821bbbb191868a7b6c8813f8481c897d9dba9?ds=sidebyside {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 --- 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)()