[latex3-commits] [git/LaTeX3-latex3-latex3] luacmd: Updated l3benchmark for LuaTeX (a36cd6767)

Marcel Fabian Krüger tex at 2krueger.de
Mon Aug 24 03:39:21 CEST 2020


Repository : https://github.com/latex3/latex3
On branch  : luacmd
Link       : https://github.com/latex3/latex3/commit/a36cd6767613f009cf06cf8dd4f18164820dcb6b

>---------------------------------------------------------------

commit a36cd6767613f009cf06cf8dd4f18164820dcb6b
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Mon Aug 24 03:22:38 2020 +0200

    Updated l3benchmark for LuaTeX


>---------------------------------------------------------------

a36cd6767613f009cf06cf8dd4f18164820dcb6b
 l3experimental/l3benchmark/l3benchmark.dtx         | 29 +++++++++++++++++-----
 ...3benchmark000.tlg => m3benchmark000.luatex.tlg} |  2 ++
 l3kernel/l3luatex.dtx                              |  8 +++---
 3 files changed, 29 insertions(+), 10 deletions(-)

diff --git a/l3experimental/l3benchmark/l3benchmark.dtx b/l3experimental/l3benchmark/l3benchmark.dtx
index 05058bdef..2a2289c59 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)*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/l3experimental/l3benchmark/testfiles/m3benchmark000.tlg b/l3experimental/l3benchmark/testfiles/m3benchmark000.luatex.tlg
similarity index 87%
copy from l3experimental/l3benchmark/testfiles/m3benchmark000.tlg
copy to l3experimental/l3benchmark/testfiles/m3benchmark000.luatex.tlg
index 455bf9d07..e41cbbd71 100644
--- a/l3experimental/l3benchmark/testfiles/m3benchmark000.tlg
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark000.luatex.tlg
@@ -2,6 +2,8 @@ This is a generated file for the LaTeX (2e + expl3) validation system.
 Don't change this file in any respect.
 (l3benchmark.sty
 Package: l3benchmark ....-..-.. L3 Experimental benchmarking
+Lua function __sys_elapsedtime: = 9
+Lua function __sys_resettimer: = 10
 \g__benchmark_nesting_int=\count...
 \g__benchmark_duration_int=\count...
 \g__benchmark_time_int=\count...
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.