[latex3-commits] [git/LaTeX3-latex3-latex3] timer: Move timer to sys (3dd8fa1ba)

Marcel Fabian Krüger tex at 2krueger.de
Tue May 11 00:20:18 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : timer
Link       : https://github.com/latex3/latex3/commit/3dd8fa1ba3d576c742ba5511e1e01e0f0c42d8f1

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

commit 3dd8fa1ba3d576c742ba5511e1e01e0f0c42d8f1
Author: Marcel Fabian Krüger <tex at 2krueger.de>
Date:   Mon Oct 5 01:47:47 2020 +0200

    Move timer to sys


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

3dd8fa1ba3d576c742ba5511e1e01e0f0c42d8f1
 l3experimental/l3benchmark/l3benchmark.dtx | 105 -----------------------------
 l3kernel/l3sys.dtx                         |  58 ++++++++++++++++
 2 files changed, 58 insertions(+), 105 deletions(-)

diff --git a/l3experimental/l3benchmark/l3benchmark.dtx b/l3experimental/l3benchmark/l3benchmark.dtx
index 7a276beea..1eec9da9e 100644
--- a/l3experimental/l3benchmark/l3benchmark.dtx
+++ b/l3experimental/l3benchmark/l3benchmark.dtx
@@ -52,26 +52,6 @@
 %
 % \begin{documentation}
 %
-% \section{Additions to \pkg{l3sys}: elapsed time}
-%
-% \begin{function}{\sys_gzero_timer:}
-%   \begin{syntax}
-%     \cs{sys_gzero_timer:}
-%   \end{syntax}
-%   Resets the timer to zero.
-% \end{function}
-%
-% \begin{function}[EXP]{\sys_timer:}
-%   \begin{syntax}
-%     \cs{sys_timer:}
-%   \end{syntax}
-%   Expands to the current value of the engine's timer clock, a
-%   non-negative integer.  In engines without clock support this expands
-%   to $0$ after an error.  In \LuaTeX{} only the CPU time is measured,
-%   while in other engines real time is measured (including time waiting
-%   for user input).
-% \end{function}
-%
 % \section{Benchmark}
 %
 % \begin{variable}{\g_benchmark_duration_target_fp}
@@ -133,91 +113,6 @@
   {L3 Experimental benchmarking}
 %    \end{macrocode}
 %
-% \subsection{Additions to \pkg{l3sys}: elapsed time}
-%
-%    \begin{macrocode}
-%<@@=sys>
-%    \end{macrocode}
-%
-% \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
-%   elapsed time will be available if this succeeds.
-%    \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:
-      { \@@_elapsedtime: }
-  }
-  {
-    \cs_if_exist:NT \tex_elapsedtime:D
-      {
-        \cs_new:Npn \sys_timer:
-          { \int_value:w \tex_elapsedtime:D }
-      }
-  }
-\@@_const:nn { sys_if_timer_exist }
-  { \cs_if_exist_p:N \sys_timer: }
-%    \end{macrocode}
-% \end{macro}
-% \end{macro}
-%
-% \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:
-  {
-    \sys_if_engine_luatex:TF
-      {
-        \cs_new_protected:Npn \sys_gzero_timer:
-          { \@@_resettimer: }
-      }
-      { \cs_new_protected:Npn \sys_gzero_timer: { \tex_resettimer:D } }
-  }
-%    \end{macrocode}
-%   If the elapsed time cannot be accessed then we define user
-%   commands to produce errors.
-%    \begin{macrocode}
-  {
-    \__kernel_msg_new:nnnn { benchmark } { no-elapsed-time }
-      { No~clock~detected~for~#1. }
-      { The~current~engine~provides~no~way~to~access~the~system~time. }
-    \cs_new_protected:Npn \sys_gzero_timer:
-      {
-        \__kernel_msg_error:nnn { benchmark } { no-elapsed-time }
-          { \sys_gzero_timer: }
-      }
-    \cs_new:Npn \sys_timer:
-      {
-        \int_value:w
-        \__kernel_msg_expandable_error:nnn { benchmark } { no-elapsed-time }
-          { \sys_timer: }
-        \c_zero_int
-      }
-  }
-%    \end{macrocode}
-% \end{macro}
-%
 % \subsection{Benchmarking code}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/l3sys.dtx b/l3kernel/l3sys.dtx
index 57f3361c5..d1115b746 100644
--- a/l3kernel/l3sys.dtx
+++ b/l3kernel/l3sys.dtx
@@ -121,6 +121,17 @@
 %   \tn{fmtname}).
 % \end{variable}
 %
+% \begin{function}[added = 2020-09-24, EXP]{\sys_timer:}
+%   \begin{syntax}
+%     \cs{sys_timer:}
+%   \end{syntax}
+%   Expands to the current value of the engine's timer clock, a
+%   non-negative integer.  This function is only defined for engines with
+%   timer support.  This command measures not just CPU time but
+%   real time (including time waiting for user input).  The unit are
+%   scaled seconds ($2^{-16}$ seconds).
+% \end{function}
+%
 % \section{Output format}
 %
 % \begin{function}[added = 2015-09-19, EXP, pTF]
@@ -863,6 +874,53 @@ end
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}[EXP]{\sys_timer:, \@@_elapsedtime:}
+% \begin{macro}[EXP, pTF]{\sys_if_timer_exist:}
+%   In \LuaTeX{}, create a pseudo-primitve, otherwise try to
+%   locate the real primitive.  The elapsed time will be
+%   available if this succeeds.
+%    \begin{macrocode}
+%</tex>
+%<*lua>
+  local gettimeofday = os.gettimeofday
+  local epoch = gettimeofday() - os.clock()
+  local write = tex.write
+  local tointeger = math.tointeger
+  luacmd('@@_elapsedtime:', function()
+    write(tointeger((gettimeofday() - epoch)*65536 // 1))
+  end, 'global')
+%</lua>
+%<*tex>
+\sys_if_engine_luatex:TF
+  {
+    \cs_new:Npn \sys_timer:
+      { \@@_elapsedtime: }
+  }
+  {
+    \cs_if_exist:NTF \tex_elapsedtime:D
+      {
+        \cs_new:Npn \sys_timer:
+          { \int_value:w \tex_elapsedtime:D }
+      }
+      {
+        \__kernel_msg_new:nnnn { kernel } { no-elapsed-time }
+          { No~clock~detected~for~#1. }
+          { The~current~engine~provides~no~way~to~access~the~system~time. }
+        \cs_new:Npn \sys_timer:
+          {
+            \int_value:w
+            \__kernel_msg_expandable_error:nnn { kernel } { no-elapsed-time }
+              { \sys_timer: }
+            \c_zero_int
+          }
+      }
+  }
+\@@_const:nn { sys_if_timer_exist }
+  { \cs_if_exist_p:N \tex_elapsedtime:D || \cs_if_exist_p:N \@@_elapsedtime: }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \subsubsection{Access to the shell}
 %
 % \begin{variable}{\c_sys_shell_escape_int}





More information about the latex3-commits mailing list.