[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add timer functions to l3luatex Lua code (c68647a)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed Oct 24 08:34:52 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/c68647adf30f316586392af475769c591c2ad809

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

commit c68647adf30f316586392af475769c591c2ad809
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Wed Oct 24 07:34:52 2018 +0100

    Add timer functions to l3luatex Lua code
    
    This will enable l3benchmark to use our own code, rather than
    pdftexcmds.


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

c68647adf30f316586392af475769c591c2ad809
 l3kernel/l3luatex.dtx |   36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/l3kernel/l3luatex.dtx b/l3kernel/l3luatex.dtx
index d6f0525..b598216 100644
--- a/l3kernel/l3luatex.dtx
+++ b/l3kernel/l3luatex.dtx
@@ -131,6 +131,14 @@
 %   the result to \TeX{}.
 % \end{function}
 %
+% \begin{function}{l3kernel.elapsedtime}
+%   \begin{syntax}
+%     |l3kernel.elapsedtime||()|
+%   \end{syntax}
+%  Returns the time in \meta{scaled seconds} since the start of the \TeX{} run
+%  or since |l3kernel.resettimer| was issued.
+% \end{function}
+%
 % \begin{function}{l3kernel.filemdfivesum}
 %   \begin{syntax}
 %     |l3kernel.filemdfivesum||(|\meta{file}|)|
@@ -164,6 +172,13 @@
 %   found, nothing is returned with \emph{no error raised}.
 % \end{function}
 %
+% \begin{function}{l3kernel.resettimer}
+%   \begin{syntax}
+%     |l3kernel.resettimer||()|
+%   \end{syntax}
+%  Resets the timer used by |l3kernel.elapsetime|.
+% \end{function}
+%
 % \begin{function}{l3kernel.strcmp}
 %   \begin{syntax}
 %     |l3kernel.strcmp||(|\meta{str one}, \meta{str two}|)|
@@ -322,6 +337,7 @@ local kpse_find  = kpse.find_file
 local lfs_attr   = lfs.attributes
 local md5_sum    = md5.sum
 local open       = io.open
+local os_clock   = os.clock
 local os_date    = os.date
 local setcatcode = tex.setcatcode
 local str_format = string.format
@@ -357,6 +373,26 @@ l3kernel.charcat = charcat
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{l3kernel.elapsedtime, l3kernel.resettimer}
+%   Simple timing set up: give the result from the system clock in scaled
+%   seconds.
+%    \begin{macrocode}
+local base_time = 0
+local function elapsedtime()
+  local val = (os_clock() - base_time) * 65536 + 0.5
+  if val > 2147483647 then
+    val = 2147483647
+  end
+  write(format("%d",val))
+end
+l3kernel.elapsedtime = elapsedtime
+local function resettimer()
+  base_time = 0
+end
+l3kernel.resettimer = resettimer
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{l3kernel.filemdfivesum}
 %   Read an entire file and hash it: the hash function itself is a built-in.
 %   As Lua is byte-based there is no work needed here in terms of UTF-8





More information about the latex3-commits mailing list