Skip to content

Instantly share code, notes, and snippets.

@jgrahamc
Created April 4, 2013 12:27
Show Gist options
  • Select an option

  • Save jgrahamc/5309954 to your computer and use it in GitHub Desktop.

Select an option

Save jgrahamc/5309954 to your computer and use it in GitHub Desktop.
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef struct timeval {
time_t tv_sec;
time_t tv_usec;
} timeval;
int gettimeofday(struct timeval* t, void* tzp);
]]
local gettimeofday_struct = ffi.new("timeval")
local function gettimeofday()
ffi.C.gettimeofday(gettimeofday_struct, nil)
return tonumber(gettimeofday_struct.tv_sec) * 1000000 +
tonumber(gettimeofday_struct.tv_usec)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment