summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/trac-inf.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tex/context/base/mkiv/trac-inf.lua')
-rw-r--r--tex/context/base/mkiv/trac-inf.lua82
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"]