Created
March 29, 2016 20:34
-
-
Save qoh/7b1ce05a3a5313290512a8aa3e9dd78b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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