[latex3-commits] [git/LaTeX3-latex3-latex3] luacmd: Updated l3benchmark for LuaTeX (17dcc7a97)
Marcel Fabian Krüger
tex at 2krueger.de
Mon Aug 24 03:22:38 CEST 2020
Repository : https://github.com/latex3/latex3
On branch : luacmd
Link : https://github.com/latex3/latex3/commit/17dcc7a973ccc33d98f0b6ba801acf4485c19288
>---------------------------------------------------------------
commit 17dcc7a973ccc33d98f0b6ba801acf4485c19288
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date: Mon Aug 24 03:22:38 2020 +0200
Updated l3benchmark for LuaTeX
>---------------------------------------------------------------
17dcc7a973ccc33d98f0b6ba801acf4485c19288
l3experimental/l3benchmark/l3benchmark.dtx | 29 +++++++++++++++++++++++------
l3kernel/l3luatex.dtx | 8 ++++----
2 files changed, 27 insertions(+), 10 deletions(-)
diff --git a/l3experimental/l3benchmark/l3benchmark.dtx b/l3experimental/l3benchmark/l3benchmark.dtx
index 05058bdef..bc063625b 100644
--- a/l3experimental/l3benchmark/l3benchmark.dtx
+++ b/l3experimental/l3benchmark/l3benchmark.dtx
@@ -139,7 +139,7 @@
%<@@=sys>
% \end{macrocode}
%
-% \begin{macro}[EXP]{\sys_timer:}
+% \begin{macro}[EXP]{\sys_timer:, \@@_elapsedtime:, \@@_resettimer:}
% \begin{macro}[EXP,pTF]{\sys_if_timer_exist:}
% In \LuaTeX{}, use emulation (see \pkg{l3luatex}),
% otherwise try to locate the primitive. The
@@ -147,8 +147,27 @@
% \begin{macrocode}
\sys_if_engine_luatex:TF
{
+ \cs_new:Npn \@@_elapsedtime: { }
+ \cs_new:Npn \@@_resettimer: { }
+ \lua_now:n
+ {
+ local~gettimeofday = os.gettimeofday~
+ local~epoch = gettimeofday() - os.clock()~
+ local~write = tex.write~
+ local~tointeger = math.tointeger~
+ local~id = luatexbase.new_luafunction'@@_elapsedtime:'
+ lua.get_functions_table()[id] = function()
+ write(tointeger((gettimeofday() - epoch + 32768)*65536 // 1))
+ end~
+ token.set_lua('@@_elapsedtime:', id, 'global')
+ id = luatexbase.new_luafunction'@@_resettimer:'
+ lua.get_functions_table()[id] = function()
+ epoch = gettimeofday()
+ end~
+ token.set_lua('@@_resettimer:', id, 'global', 'protected')
+ }
\cs_new:Npn \sys_timer:
- { \lua_now:n { l3kernel.elapsedtime() } }
+ { \@@_elapsedtime: }
}
{
\cs_if_exist:NT \tex_elapsedtime:D
@@ -163,8 +182,7 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\sys_gzero_timer:, \@@_timer_fp:}
-% \begin{variable}{\g_@@_timer_base_fp}
+% \begin{macro}{\sys_gzero_timer:}
% Three case, and in each case we define \cs{sys_gzero_timer:}.
% \begin{macrocode}
\cs_if_exist:NTF \sys_timer:
@@ -172,7 +190,7 @@
\sys_if_engine_luatex:TF
{
\cs_new_protected:Npn \sys_gzero_timer:
- { \lua_now:n { l3kernel.resettimer() } }
+ { \@@_resettimer: }
}
{ \cs_new_protected:Npn \sys_gzero_timer: { \tex_resettimer:D } }
}
@@ -198,7 +216,6 @@
}
}
% \end{macrocode}
-% \end{variable}
% \end{macro}
%
% \subsection{Benchmarking code}
diff --git a/l3kernel/l3luatex.dtx b/l3kernel/l3luatex.dtx
index 3e1c58679..c02e6a3ca 100644
--- a/l3kernel/l3luatex.dtx
+++ b/l3kernel/l3luatex.dtx
@@ -358,7 +358,6 @@ local format = string.format
local gsub = string.gsub
local lfs_attr = lfs.attributes
local open = io.open
-local os_clock = os.clock
local os_date = os.date
local setcatcode = tex.setcatcode
local sprint = tex.sprint
@@ -414,9 +413,10 @@ end)
% Simple timing set up: give the result from the system clock in scaled
% seconds.
% \begin{macrocode}
-local base_time = 0
+local os_clock = os.clock
+local base_clock_time = 0
local function elapsedtime()
- local val = (os_clock() - base_time) * 65536 + 0.5
+ local val = (os_clock() - base_clock_time) * 65536 + 0.5
if val > 2147483647 then
val = 2147483647
end
@@ -424,7 +424,7 @@ local function elapsedtime()
end
l3kernel.elapsedtime = elapsedtime
local function resettimer()
- base_time = os_clock()
+ base_clock_time = os_clock()
end
l3kernel.resettimer = resettimer
% \end{macrocode}
More information about the latex3-commits
mailing list.