Skip to content

Instantly share code, notes, and snippets.

@qoh
Created March 29, 2016 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qoh/7b1ce05a3a5313290512a8aa3e9dd78b to your computer and use it in GitHub Desktop.
Save qoh/7b1ce05a3a5313290512a8aa3e9dd78b to your computer and use it in GitHub Desktop.
local ffi = require "ffi"
ffi.cdef [[
bool QueryPerformanceFrequency(int64_t *lpFrequency);
bool QueryPerformanceCounter(int64_t *lpPerformanceCount);
]]
local ptr_freq = ffi.new("int64_t[1]")
local ptr_tick = ffi.new("int64_t[1]")
local function get_time()
if not ffi.C.QueryPerformanceFrequency(ptr_freq) then
error("QueryPerformanceFrequency() failed")
end
if not ffi.C.QueryPerformanceCounter(ptr_tick) then
error("QueryPerformanceCounter() failed")
end
return tonumber(ptr_tick[0]) / tonumber(ptr_freq[0])
end
local time_start
function _G.perfStart()
time_start = get_time()
end
function _G.perfEnd(name)
local time_total = get_time() - time_start
print(name .. ": " .. time_total * 1000 .. " ms")
end
_G.ts.expose("perfStart")
_G.ts.expose("perfEnd")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment