[latex3-commits] [git/LaTeX3-latex3-latex3] main: l3benchmark: Store results in a variable (#918) (768cb420d)

GitHub noreply at github.com
Sat May 15 21:35:48 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/768cb420d3e1c0d442165e87faa318a2caebc54d

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

commit 768cb420d3e1c0d442165e87faa318a2caebc54d
Author: Skillmon <Skillmon at users.noreply.github.com>
Date:   Sat May 15 21:35:48 2021 +0200

    l3benchmark: Store results in a variable (#918)
    
    Add silent benchmark variants; make results public


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

768cb420d3e1c0d442165e87faa318a2caebc54d
 l3experimental/CHANGELOG.md                        |  7 +++
 l3experimental/l3benchmark/l3benchmark.dtx         | 51 +++++++++++++++-------
 .../l3benchmark/testfiles/m3benchmark001.lvt       | 10 ++---
 .../l3benchmark/testfiles/m3benchmark002.lvt       | 42 ++++++++++++++++++
 .../l3benchmark/testfiles/m3benchmark002.tlg       |  8 ++--
 5 files changed, 94 insertions(+), 24 deletions(-)

diff --git a/l3experimental/CHANGELOG.md b/l3experimental/CHANGELOG.md
index 2180a6864..f417538d7 100644
--- a/l3experimental/CHANGELOG.md
+++ b/l3experimental/CHANGELOG.md
@@ -7,6 +7,13 @@ this project uses date-based 'snapshot' version identifiers.
 
 ## [Unreleased]
 
+### Added
+- `\benchmark_silent:n` and `\benchmark_once_silent:n` added to `l3benchmark`
+
+### Changed
+- store results of `l3benchmark` in documented user-level instead of private
+  variables
+
 ## [2021-02-18]
 
 ### Removed
diff --git a/l3experimental/l3benchmark/l3benchmark.dtx b/l3experimental/l3benchmark/l3benchmark.dtx
index 1eec9da9e..c4cccbe16 100644
--- a/l3experimental/l3benchmark/l3benchmark.dtx
+++ b/l3experimental/l3benchmark/l3benchmark.dtx
@@ -63,6 +63,14 @@
 %   than this.
 % \end{variable}
 %
+% \begin{variable}{\g_benchmark_time_fp, \g_benchmark_ops_fp}
+%   These variables store the results of the most recently run benchmark.
+%   \cs{g_benchmark_time_fp} stores the time \TeX{} took, and
+%   \cs{g_benchmark_ops_fp} stores the estimated number of elementary
+%   operations. The latter is not set by
+%   \cs{benchmark_tic:}/\cs{benchmark_toc:}.
+% \end{variable}
+%
 % \begin{function}{\benchmark_once:n}
 %   \begin{syntax}
 %     \cs{benchmark_once:n} \Arg{code}
@@ -137,6 +145,8 @@
     \cs_new_protected:Npn \benchmark_once:n #1
       { \msg_error:nn { benchmark } { no-time } }
     \cs_new_eq:NN \benchmark:n \benchmark_once:n
+    \cs_new_eq:NN \benchmark_once_silent:n \benchmark_once:n
+    \cs_new_eq:NN \benchmark_silent:n \benchmark_once:n
     \cs_new_protected:Npn \benchmark_tic:
       { \msg_error:nn { benchmark } { no-time } }
     \cs_new_eq:NN \benchmark_toc: \benchmark_tic:
@@ -232,13 +242,13 @@
 %
 % \subsubsection{Main benchmarking}
 %
-% \begin{variable}{\g_@@_time_fp, \g_@@_ops_fp}
+% \begin{variable}{\g_benchmark_time_fp, \g_benchmark_ops_fp}
 %   Functions such as \cs{benchmark:n} store the measured time in
-%   \cs{g_@@_time_fp} (in seconds) and the estimated number of
-%   operations in \cs{g_@@_ops_fp}.
+%   \cs{g_benchmark_time_fp} (in seconds) and the estimated number of
+%   operations in \cs{g_benchmark_ops_fp}.
 %    \begin{macrocode}
-\fp_new:N \g_@@_time_fp
-\fp_new:N \g_@@_ops_fp
+\fp_new:N \g_benchmark_time_fp
+\fp_new:N \g_benchmark_ops_fp
 %    \end{macrocode}
 % \end{variable}
 %
@@ -276,18 +286,23 @@
 %    \end{macrocode}
 % \end{variable}
 %
-% \begin{macro}{\benchmark_once:n}
+% \begin{macro}{\benchmark_once:n, \benchmark_once_silent:n}
 %   Convert the raw time from scaled seconds to seconds, and convert to
 %   a number of operations.  It is important to measure the elementary
 %   operation before running the user code because both measurements use
 %   the same temporary variables.
 %    \begin{macrocode}
 \cs_new_protected:Npn \benchmark_once:n #1
+  {
+    \benchmark_once_silent:n {#1}
+    \@@_display:
+  }
+\cs_new_protected:Npn \benchmark_once_silent:n #1
   {
     \@@_measure_op:
     \@@_raw:nN {#1} \g_@@_time_int
-    \fp_gset:Nn \g_@@_time_fp { \g_@@_time_int / 65536 }
-    \@@_display:
+    \fp_gset:Nn \g_benchmark_time_fp { \g_@@_time_int / 65536 }
+    \fp_gset:Nn \g_benchmark_ops_fp { \g_benchmark_time_fp / \g_@@_one_op_fp }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -296,11 +311,16 @@
 %   After setting up some variables the work is done by \cs{@@_aux:}.
 %    \begin{macrocode}
 \cs_new_protected:Npn \benchmark:n #1
+  {
+    \benchmark_silent:n {#1}
+    \@@_display:
+  }
+\cs_new_protected:Npn \benchmark_silent:n #1
   {
     \@@_measure_op:
     \tl_gset:Nn \g_@@_code_tl {#1}
     \@@_aux:
-    \@@_display:
+    \fp_gset:Nn \g_benchmark_ops_fp { \g_benchmark_time_fp / \g_@@_one_op_fp }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -355,7 +375,7 @@
       }
     \prg_break_point:
     \int_compare:nNnT \g_@@_time_int < 3 { \int_gzero:N \g_@@_time_int }
-    \fp_gset:Nn \g_@@_time_fp
+    \fp_gset:Nn \g_benchmark_time_fp
       { \g_@@_time_int / \g_@@_repeat_int / 65536 }
   }
 \cs_new_protected:Npn \@@_run:N
@@ -383,7 +403,7 @@
     \tl_gset:Nn \g_@@_code_tl
       { \int_gadd:Nn \g_@@_duration_int { 0 } }
     \@@_aux:
-    \fp_gset:Nn \g_@@_one_op_fp { max(\g_@@_time_fp, 1e-16) }
+    \fp_gset:Nn \g_@@_one_op_fp { max(\g_benchmark_time_fp, 1e-16) }
     \int_gset:Nn \g_@@_duration_int
       { \fp_to_int:n { 65536 * \g_benchmark_duration_target_fp } }
   }
@@ -414,11 +434,10 @@
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_display:
   {
-    \fp_gset:Nn \g_@@_ops_fp { \g_@@_time_fp / \g_@@_one_op_fp }
     \iow_term:x
       {
-        \@@_fp_to_tl:N \g_@@_time_fp \c_space_tl seconds \c_space_tl
-        ( \@@_fp_to_tl:N \g_@@_ops_fp \c_space_tl ops)
+        \@@_fp_to_tl:N \g_benchmark_time_fp \c_space_tl seconds \c_space_tl
+        ( \@@_fp_to_tl:N \g_benchmark_ops_fp \c_space_tl ops)
       }
   }
 %    \end{macrocode}
@@ -468,13 +487,13 @@
 \cs_new_protected:Npn \@@_toc:
   {
     \int_gdecr:N \g_@@_tictoc_int
-    \fp_gset:Nn \g_@@_time_fp
+    \fp_gset:Nn \g_benchmark_time_fp
       { ( \sys_timer: - \l_@@_tictoc_pop_tl ) / 65536 }
     \iow_term:x
       {
         \@@_tictoc_prefix:
         TOC: \c_space_tl
-        \@@_fp_to_tl:N \g_@@_time_fp \c_space_tl s
+        \@@_fp_to_tl:N \g_benchmark_time_fp \c_space_tl s
       }
   }
 \msg_new:nnn { benchmark } { toc-first }
diff --git a/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt b/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt
index f40fbc478..3d28c3972 100644
--- a/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark001.lvt
@@ -44,9 +44,9 @@
     \int_gzero:N \g_tmpa_int
     \test_disable_iow:n { \benchmark_once:n { \int_gincr:N \g_tmpa_int } }
     \int_log:N \g_tmpa_int    % Check the code was done only once
-    \fp_compare:nTF { \g__benchmark_time_fp < 5e-5 }  % Check it took 0 to 3 scaled seconds
+    \fp_compare:nTF { \g_benchmark_time_fp < 5e-5 }  % Check it took 0 to 3 scaled seconds
       { \TRUE }
-      { \ERROR \fp_show:N \g__benchmark_time_fp }
+      { \ERROR \fp_show:N \g_benchmark_time_fp }
   }
 
 \TEST { benchmark }
@@ -56,9 +56,9 @@
     \prg_replicate:nn { 3 }
       {
         \test_disable_iow:n { \benchmark:n { \test_slow_code: } }
-        \clist_put_right:Nx \l_tmpa_clist { \fp_to_tl:N \g__benchmark_time_fp }
+        \clist_put_right:Nx \l_tmpa_clist { \fp_to_tl:N \g_benchmark_time_fp }
         \test_disable_iow:n { \benchmark:n { \test_slow_code: \test_slow_code: } }
-        \clist_put_right:Nx \l_tmpb_clist { \fp_to_tl:N \g__benchmark_time_fp }
+        \clist_put_right:Nx \l_tmpb_clist { \fp_to_tl:N \g_benchmark_time_fp }
       }
     \fp_compare:nTF % Check that doing code twice takes between 1.5 and 2.5 times as much
       {
@@ -80,7 +80,7 @@
       \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 }
+          \fp_gset:Nn \g_benchmark_time_fp { 1.2 }
           \test_iow_term:x
         }
       #1
diff --git a/l3experimental/l3benchmark/testfiles/m3benchmark002.lvt b/l3experimental/l3benchmark/testfiles/m3benchmark002.lvt
new file mode 100644
index 000000000..50d5f864b
--- /dev/null
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark002.lvt
@@ -0,0 +1,42 @@
+\documentclass{minimal}
+\input{regression-test}
+
+\RequirePackage[enable-debug]{expl3}
+\RequirePackage{l3benchmark}
+\ExplSyntaxOn
+\debug_on:n { check-declarations , deprecation , log-functions }
+\ExplSyntaxOff
+
+\START
+\ExplSyntaxOn
+
+\fp_gset:Nn \g_benchmark_duration_target_fp { 0.01 }
+
+\OMIT
+\fp_new:N \l_test_fast_fp
+\fp_new:N \l_test_slow_fp
+\exp_args:NNx \seq_set_from_clist:Nn \l_tmpa_seq
+  { \prg_replicate:nn { 123 } { a , } }
+\cs_new_protected:Npn \test_slow_code:
+  { \seq_reverse:N \l_tmpa_seq }
+\TIMO
+
+\TEST { benchmark_silent }
+  {
+    \benchmark_silent:n { \prg_do_nothing: }
+    \fp_set_eq:NN \l_test_fast_fp \g_benchmark_ops_fp
+    \benchmark_silent:n { \int_zero:N \l_tmpa_int }
+    \fp_set_eq:NN \l_test_slow_fp \g_benchmark_ops_fp
+    \fp_compare:nNnTF \l_test_fast_fp < \l_test_slow_fp
+      { \TRUE }
+      { \FAST }
+    \benchmark_once_silent:n { \prg_do_nothing: }
+    \fp_set_eq:NN \l_test_fast_fp \g_benchmark_ops_fp
+    \benchmark_once_silent:n { \test_slow_code: }
+    \fp_set_eq:NN \l_test_slow_fp \g_benchmark_ops_fp
+    \fp_compare:nNnTF \l_test_fast_fp < \l_test_slow_fp
+      { \TRUE }
+      { \FAST }
+  }
+
+\END
diff --git a/l3kernel/testfiles/m3token001.tlg b/l3experimental/l3benchmark/testfiles/m3benchmark002.tlg
similarity index 73%
copy from l3kernel/testfiles/m3token001.tlg
copy to l3experimental/l3benchmark/testfiles/m3benchmark002.tlg
index cd844648d..aa0cdc234 100644
--- a/l3kernel/testfiles/m3token001.tlg
+++ b/l3experimental/l3benchmark/testfiles/m3benchmark002.tlg
@@ -1,8 +1,10 @@
 This is a generated file for the LaTeX (2e + expl3) validation system.
 Don't change this file in any respect.
-Author: Joseph Wright
 ============================================================
-TEST 1: Unicode NFD
+TEST 1: benchmark_silent
 ============================================================
-A
+Defining \g__benchmark_1_int on line ...
+\g__benchmark_1_int=\count...
+TRUE
+TRUE
 ============================================================





More information about the latex3-commits mailing list.