[latex3-commits] [git/LaTeX3-latex3-latex3] master: Clean up benchmark tic/toc code, tweak output, add tests (0f291b5)

Bruno Le Floch bruno at le-floch.fr
Sun Nov 4 21:29:58 CET 2018


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

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

commit 0f291b51447811ea1e19a725e22ec3923165182a
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Sun Nov 4 21:27:39 2018 +0100

    Clean up benchmark tic/toc code, tweak output, add tests


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

0f291b51447811ea1e19a725e22ec3923165182a
 l3experimental/l3benchmark/l3benchmark.dtx         |   51 ++++++++++----------
 .../l3benchmark/testfiles/m3benchmark001.lvt       |   30 ++++++++++++
 .../l3benchmark/testfiles/m3benchmark001.tlg       |   24 +++++++++
 .../l3benchmark/testfiles/m3benchmark001.xetex.tlg |   12 +++++
 4 files changed, 91 insertions(+), 26 deletions(-)

diff --git a/l3experimental/l3benchmark/l3benchmark.dtx b/l3experimental/l3benchmark/l3benchmark.dtx
index 805eea9..4408ff3 100644
--- a/l3experimental/l3benchmark/l3benchmark.dtx
+++ b/l3experimental/l3benchmark/l3benchmark.dtx
@@ -108,8 +108,8 @@
 %   tic/toc commands can be used instead to time between two points in
 %   the code.  When executed, \cs{benchmark_tic:} will print a line to the
 %   terminal, and \cs{benchmark_toc:} will print a matching line with a
-%   time to indicate the duration between them in seconds.  Note that
-%   these commands can be nested.
+%   time to indicate the duration between them in seconds.
+%   These commands can be nested.
 % \end{function}
 %
 % \end{documentation}
@@ -512,33 +512,33 @@
 %
 % \subsection{Benchmark tic toc}
 %
-% \begin{variable}{\g_@@_tictoc_int, \g_@@_tictoc_seq}
+% \begin{variable}{\g_@@_tictoc_int, \g_@@_tictoc_seq, \l_@@_tictoc_pop_tl}
 %    \begin{macrocode}
 \int_new:N \g_@@_tictoc_int
 \seq_new:N \g_@@_tictoc_seq
+\tl_new:N \l_@@_tictoc_pop_tl
 %    \end{macrocode}
 % \end{variable}
 %
-% \begin{macro}{\benchmark_tic:, \@@_tic:}
+% \begin{macro}[EXP]{\@@_tictoc_prefix:}
+%   We include the package name in analogy with continuation lines of
+%   error/warning messages.
 %    \begin{macrocode}
-\cs_new_protected:Npn \benchmark_tic:
+\cs_new:Npn \@@_tictoc_prefix:
   {
-    \int_compare:nTF { \g_@@_tictoc_int == 0 }
-      {
-        \sys_gzero_timer:
-        \@@_tic:
-      }
-      { \@@_tic: }
+    (l3benchmark) \c_space_tl
+    + \prg_replicate:nn { \g_@@_tictoc_int } { -+ } \c_space_tl
   }
-\cs_new_protected:Npn \@@_tic:
+%    \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\benchmark_tic:}
+%    \begin{macrocode}
+\cs_new_protected:Npn \benchmark_tic:
   {
-    \exp_args:NNf \seq_put_right:Nn \g_@@_tictoc_seq { \sys_timer: }
+    \iow_term:x { \@@_tictoc_prefix: TIC }
+    \exp_args:NNf \seq_gput_right:Nn \g_@@_tictoc_seq { \sys_timer: }
     \int_gincr:N \g_@@_tictoc_int
-    \iow_term:x
-      {
-        \prg_replicate:nn {\g_@@_tictoc_int} {---+} \space
-        TIC
-      }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -547,24 +547,23 @@
 %    \begin{macrocode}
 \cs_new:Npn \benchmark_toc:
   {
-    \int_compare:nT { \g_@@_tictoc_int == 0 }
-      { \msg_error:nn {benchmark} {toc-first} }
-    \seq_pop_right:NN \g_@@_tictoc_seq \l_@@_tictoc_pop_tl
-    \@@_toc:
+    \seq_gpop_right:NNTF \g_@@_tictoc_seq \l_@@_tictoc_pop_tl
+      { \@@_toc: }
+      { \msg_error:nn { benchmark } { toc-first } }
   }
 \cs_new_protected:Npn \@@_toc:
   {
+    \int_gdecr:N \g_@@_tictoc_int
     \fp_gset:Nn \g_@@_time_fp
-      { ( \sys_timer: - \l_@@_tictoc_pop_tl) / 65536 }
+      { ( \sys_timer: - \l_@@_tictoc_pop_tl ) / 65536 }
     \iow_term:x
       {
-        \prg_replicate:nn {\g_@@_tictoc_int} {---+} \c_space_tl
+        \@@_tictoc_prefix:
         TOC: \c_space_tl
         \@@_fp_to_tl:N \g_@@_time_fp \c_space_tl s
       }
-    \int_gdecr:N \g_@@_tictoc_int
   }
-\msg_new:nnn {benchmark} {toc-first}
+\msg_new:nnn { benchmark } { toc-first }
   {
     \token_to_str:N \benchmark_toc: \c_space_tl without~
     \token_to_str:N \benchmark_tic: \c_space_tl !
diff --git a/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt b/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt
index a1b4dc4..98cec7f 100644
--- a/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt
@@ -18,6 +18,8 @@
   {
     \benchmark_once:n \ERROR \TRUE
     \benchmark:n \ERROR \TRUE
+    \benchmark_tic: \TRUE
+    \benchmark_toc: \TRUE
     \END
   }
 
@@ -71,4 +73,32 @@
       }
   }
 
+\OMIT
+\cs_new_protected:Npn \test_reset_time_at_iow:n #1
+  {
+    \group_begin:
+      \cs_set_eq:NN \test_iow_term:x \iow_term:x
+      \cs_set_protected:Npn \iow_term:x
+        {
+          \fp_gset:Nn \g__benchmark_time_fp { 1.2 }
+          \test_iow_term:x
+        }
+      #1
+    \group_end:
+  }
+\TIMO
+
+\TEST { tic/toc }
+  {
+    \benchmark_toc:
+    \benchmark_toc:
+    \int_gzero:N \g_tmpa_int
+    \group_begin:
+      \prg_replicate:nn { 3 } { \benchmark_tic: }
+      \int_gincr:N \g_tmpa_int
+    \group_end:
+    \test_reset_time_at_iow:n { \prg_replicate:nn { 3 } { \benchmark_toc: } }
+    \int_compare:nNnF \g_tmpa_int = 1 { \ERROR } % Check the code was done only once
+  }
+
 \END
diff --git a/l3experimental/l3benchmark/testfiles/m3benchmark001.tlg b/l3experimental/l3benchmark/testfiles/m3benchmark001.tlg
index 78338f6..97fb2c7 100644
--- a/l3experimental/l3benchmark/testfiles/m3benchmark001.tlg
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark001.tlg
@@ -13,3 +13,27 @@ TEST 2: benchmark
 ============================================================
 TRUE
 ============================================================
+============================================================
+TEST 3: tic/toc
+============================================================
+! Package benchmark Error: \benchmark_toc: without \benchmark_tic: !
+Type <return> to continue.
+ ...                                              
+l. ...  }
+LaTeX does not know anything more about this error, sorry.
+Try typing <return> to proceed.
+If that doesn't work, type X <return> to quit.
+! Package benchmark Error: \benchmark_toc: without \benchmark_tic: !
+Type <return> to continue.
+ ...                                              
+l. ...  }
+LaTeX does not know anything more about this error, sorry.
+Try typing <return> to proceed.
+If that doesn't work, type X <return> to quit.
+(l3benchmark) + TIC
+(l3benchmark) +-+ TIC
+(l3benchmark) +-+-+ TIC
+(l3benchmark) +-+-+ TOC: 1.2 s
+(l3benchmark) +-+ TOC: 1.2 s
+(l3benchmark) + TOC: 1.2 s
+============================================================
diff --git a/l3experimental/l3benchmark/testfiles/m3benchmark001.xetex.tlg b/l3experimental/l3benchmark/testfiles/m3benchmark001.xetex.tlg
index 58c1f9c..bd5f01b 100644
--- a/l3experimental/l3benchmark/testfiles/m3benchmark001.xetex.tlg
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark001.xetex.tlg
@@ -12,3 +12,15 @@ For immediate help type H <return>.
 l. ...  }
 The current engine provides no way to access the system time.
 TRUE
+! Package benchmark Error: The l3benchmark package failed to access a clock.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+The current engine provides no way to access the system time.
+TRUE
+! Package benchmark Error: The l3benchmark package failed to access a clock.
+For immediate help type H <return>.
+ ...                                              
+l. ...  }
+The current engine provides no way to access the system time.
+TRUE





More information about the latex3-commits mailing list