diff options
author | Hans Hagen <pragma@wxs.nl> | 2020-02-17 16:17:51 +0100 |
---|---|---|
committer | Context Git Mirror Bot <phg@phi-gamma.net> | 2020-02-17 16:17:51 +0100 |
commit | 631a40d69d7fb4e5beff90039d21da5472dd1020 (patch) | |
tree | 8e9d9dc68c506fe309ccef784fe4b59853e98add /tex/context/base/mkiv/trac-inf.lua | |
parent | 8e11d447440b44990432ac838953a8cde4ef914f (diff) | |
download | context-631a40d69d7fb4e5beff90039d21da5472dd1020.tar.gz |
2020-02-17 12:10:00
Diffstat (limited to 'tex/context/base/mkiv/trac-inf.lua')
-rw-r--r-- | tex/context/base/mkiv/trac-inf.lua | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/tex/context/base/mkiv/trac-inf.lua b/tex/context/base/mkiv/trac-inf.lua index 24ebc5249..40dfe854e 100644 --- a/tex/context/base/mkiv/trac-inf.lua +++ b/tex/context/base/mkiv/trac-inf.lua @@ -45,42 +45,52 @@ end local ticks = clock local seconds = function(n) return n or 0 end --- if FFISUPPORTED and ffi and os.type == "windows" then --- --- local okay, kernel = pcall(ffi.load,"kernel32") --- --- if kernel then --- --- local tonumber = ffi.number or tonumber --- --- ffi.cdef[[ --- int QueryPerformanceFrequency(int64_t *lpFrequency); --- int QueryPerformanceCounter(int64_t *lpPerformanceCount); --- ]] --- --- local target = ffi.new("__int64[1]") --- --- ticks = function() --- if kernel.QueryPerformanceCounter(target) == 1 then --- return tonumber(target[0]) --- else --- return 0 --- end --- end --- --- local target = ffi.new("__int64[1]") --- --- seconds = function(ticks) --- if kernel.QueryPerformanceFrequency(target) == 1 then --- return ticks / tonumber(target[0]) --- else --- return 0 --- end --- end --- --- end --- --- end +if lua.getpreciseticks then + + ticks = lua.getpreciseticks + seconds = lua.getpreciseseconds + +elseif FFISUPPORTED and ffi and os.type == "windows" then + + local okay, kernel = pcall(ffi.load,"kernel32") + + if kernel then + + local tonumber = ffi.number or tonumber + + ffi.cdef[[ + int QueryPerformanceFrequency(int64_t *lpFrequency); + int QueryPerformanceCounter(int64_t *lpPerformanceCount); + ]] + + local target = ffi.new("__int64[1]") + + ticks = function() + if kernel.QueryPerformanceCounter(target) == 1 then + return tonumber(target[0]) + else + return 0 + end + end + + local target = ffi.new("__int64[1]") + + seconds = function(ticks) + if kernel.QueryPerformanceFrequency(target) == 1 then + return ticks / tonumber(target[0]) + else + return 0 + end + end + + end + +else + + -- excessive timing costs some 1-2 percent runtime + +end + local function starttiming(instance,reset) local timer = timers[instance or "notimer"] |