[latex3-commits] [git/LaTeX3-latex3-latex3] master: Make \g_benchmark_duration_target_fp public (79acc4e)

Bruno Le Floch bruno at le-floch.fr
Wed May 9 00:44:28 CEST 2018


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

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

commit 79acc4ed317544fd6171a631488268ced830d860
Author: Bruno Le Floch <bruno at le-floch.fr>
Date:   Tue May 8 18:44:28 2018 -0400

    Make \g_benchmark_duration_target_fp public
    
    (mostly to avoid using internals in the test file)


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

79acc4ed317544fd6171a631488268ced830d860
 l3trial/l3benchmark/l3benchmark.dtx              |  100 ++++++++++++----------
 l3trial/l3benchmark/testfiles/m3benchmark000.tlg |   16 ++--
 l3trial/l3benchmark/testfiles/m3benchmark001.lvt |    3 +-
 3 files changed, 66 insertions(+), 53 deletions(-)

diff --git a/l3trial/l3benchmark/l3benchmark.dtx b/l3trial/l3benchmark/l3benchmark.dtx
index 7397173..4c68c3b 100644
--- a/l3trial/l3benchmark/l3benchmark.dtx
+++ b/l3trial/l3benchmark/l3benchmark.dtx
@@ -86,6 +86,14 @@
 %
 % \section{Benchmark}
 %
+% \begin{variable}{\g_benchmark_duration_target_fp}
+%   This variable controls roughly for how long \cs{benchmark:n} will
+%   repeat code to more accurately benchmark it.  The actual duration of
+%   one call to \cs{benchmark:n} typically lasts between half and twice
+%   \cs{g_benchmark_duration_target_fp} seconds, unless of course
+%   running the code only once already lasts longer than this.
+% \end{variable}
+%
 % \begin{variable}{\g_benchmark_time_fp}
 %   Functions such as \cs{benchmark:n} store the measured time in
 %   \cs{g_benchmark_time_fp} (in seconds).
@@ -355,34 +363,36 @@ end
   }
 %    \end{macrocode}
 %
-% \begin{variable}{\l_@@_duration_int}
+% \begin{variable}{\g_benchmark_duration_target_fp, \g_@@_duration_int}
 %   The benchmark is constrained to take roughly (from half to twice)
-%   \cs{l_@@_duration_int} scaled seconds, unless one iteration of the
+%   \cs{g_benchmark_duration_target_fp} seconds, more precisely
+%   \cs{g_@@_duration_int} scaled seconds, unless one iteration of the
 %   code takes longer.
 %    \begin{macrocode}
-\int_new:N \l_@@_duration_int
-\int_set:Nn \l_@@_duration_int { 65536 }
+\fp_new:N \g_benchmark_duration_target_fp
+\fp_gset:Nn \g_benchmark_duration_target_fp { 1 }
+\int_new:N \g_@@_duration_int
 %    \end{macrocode}
 % \end{variable}
 % 
-% \begin{variable}{\l_@@_time_int, \l_@@_time_a_int, \l_@@_time_b_int, \l_@@_time_c_int, \l_@@_time_d_int, \l_@@_time_median_int}
+% \begin{variable}{\g_@@_time_int, \g_@@_time_a_int, \g_@@_time_b_int, \g_@@_time_c_int, \g_@@_time_d_int, \g_@@_time_median_int}
 %   These variables hold the time for running a piece of code, as an
 %   integer in scaled seconds.
 %    \begin{macrocode}
-\int_new:N \l_@@_time_int
-\int_new:N \l_@@_time_a_int
-\int_new:N \l_@@_time_b_int
-\int_new:N \l_@@_time_c_int
-\int_new:N \l_@@_time_d_int
-\int_new:N \l_@@_time_median_int
+\int_new:N \g_@@_time_int
+\int_new:N \g_@@_time_a_int
+\int_new:N \g_@@_time_b_int
+\int_new:N \g_@@_time_c_int
+\int_new:N \g_@@_time_d_int
+\int_new:N \g_@@_time_median_int
 %    \end{macrocode}
 % \end{variable}
 %
-% \begin{variable}{\l_@@_repeat_int}
+% \begin{variable}{\g_@@_repeat_int}
 %   Holds the number of times that the piece of code was
 %   repeated when timing.
 %    \begin{macrocode}
-\int_new:N \l_@@_repeat_int
+\int_new:N \g_@@_repeat_int
 %    \end{macrocode}
 % \end{variable}
 %
@@ -411,7 +421,7 @@ end
   }
 \cs_new_protected:Npn \@@_raw_end:nN #1#2
   {
-    \int_set:Nn #2
+    \int_gset:Nn #2
       {
         #1 -
         \int_use:c { g_@@_ \int_use:N \g_@@_nesting_int _int }
@@ -429,8 +439,8 @@ end
   { \benchmark_once_silent:n {#1} \benchmark_display: }
 \cs_new_protected:Npn \benchmark_once_silent:n #1
   {
-    \@@_raw:nN {#1} \l_@@_time_int
-    \fp_gset:Nn \g_benchmark_time_fp { \l_@@_time_int / 65536 }
+    \@@_raw:nN {#1} \g_@@_time_int
+    \fp_gset:Nn \g_benchmark_time_fp { \g_@@_time_int / 65536 }
   }
 %    \end{macrocode}
 % \end{macro}
@@ -466,14 +476,14 @@ end
 \cs_new_protected:Npn \@@_raw_replicate_small:nnN #1#2
   {
     \cs_set:Npx \@@_tmp:w ##1##2 { \prg_replicate:nn {#1} {##1} }
-    \@@_raw:nN { \@@_tmp:w {#2} { } } \l_@@_time_int
+    \@@_raw:nN { \@@_tmp:w {#2} { } } \g_@@_time_int
     \exp_args:No \@@_raw_replicate_aux:nnN
-      { \int_use:N \l_@@_time_int } {#2}
+      { \int_use:N \g_@@_time_int } {#2}
   }
 \cs_new_protected:Npn \@@_raw_replicate_aux:nnN #1#2#3
   {
-    \@@_raw:nN { \@@_tmp:w { } {#2} } \l_@@_time_int
-    \int_set:Nn #3 { #1 - \l_@@_time_int }
+    \@@_raw:nN { \@@_tmp:w { } {#2} } \g_@@_time_int
+    \int_gset:Nn #3 { #1 - \g_@@_time_int }
   }
 \cs_new:Npx \@@_replicate_kibi_fold:n #1
   { \prg_replicate:nn {1024} {#1} }
@@ -484,12 +494,12 @@ end
 %    \begin{macrocode}
 \cs_new_protected:Npn \@@_set_median:
   {
-    \@@_set_median:NNNN \l_@@_time_a_int \l_@@_time_b_int
-      \l_@@_time_c_int \l_@@_time_d_int
+    \@@_set_median:NNNN \g_@@_time_a_int \g_@@_time_b_int
+      \g_@@_time_c_int \g_@@_time_d_int
   }
 \cs_new_protected:Npn \@@_set_median:NNNN #1#2#3#4
   {
-    \int_set:Nn \l_@@_time_median_int
+    \int_gset:Nn \g_@@_time_median_int
       {
         ( #1 + #2 + #3 + #4
         - \int_min:nn { \int_min:nn #1 #2 } { \int_min:nn #3 #4 }
@@ -507,49 +517,53 @@ end
 %   zero time).  Once we reach a reasonable time, compute a number of
 %   times that can fit in one quarter of a second and measure that four
 %   times.  To save time we reuse the result of the first pass if
-%   \cs{l_@@_repeat_int} is one.  Once we have four results, take their
+%   \cs{g_@@_repeat_int} is one.  Once we have four results, take their
 %   median and display that, divided by $65536$ and by the number of
 %   repetitions.
 %    \begin{macrocode}
 \tl_new:N \g_@@_code_tl
-\fp_new:N \l_@@_time_fp
 \cs_new_protected:Npn \benchmark:n #1
   { \benchmark_silent:n {#1} \benchmark_display: }
 \cs_new_protected:Npn \benchmark_silent:n #1
   {
-    \int_set:Nn \l_@@_repeat_int { 1 }
+    \int_gset:Nn \g_@@_duration_int
+      { \fp_to_int:n { 65536 * \g_benchmark_duration_target_fp } }
+    \int_gset:Nn \g_@@_repeat_int { 1 }
     \tl_gset:Nn \g_@@_code_tl {#1}
-    \@@_raw:nN { \g_@@_code_tl } \l_@@_time_int
-    \int_compare:nNnF \l_@@_time_int < { \l_@@_duration_int / 2 }
+    \@@_raw:nN { \g_@@_code_tl } \g_@@_time_int
+    \int_compare:nNnF \g_@@_time_int < { \g_@@_duration_int / 2 }
       { \prg_break: }
-    \int_while_do:nNnn \l_@@_time_int < { \l_@@_duration_int / 100 }
+    \int_while_do:nNnn \g_@@_time_int < { \g_@@_duration_int / 100 }
       {
-        \int_compare:nNnT \l_@@_repeat_int > { \c_max_int / 4 }
+        \int_compare:nNnT \g_@@_repeat_int > { \c_max_int / 4 }
           {
-            \int_set:Nn \l_@@_time_median_int { 0 }
+            \int_gset:Nn \g_@@_time_median_int { 0 }
             \prg_break:
           }
-        \int_set:Nn \l_@@_repeat_int { 4 * \l_@@_repeat_int }
-        \@@_run:N \l_@@_time_int
+        \int_gset:Nn \g_@@_repeat_int { 4 * \g_@@_repeat_int }
+        \@@_run:N \g_@@_time_int
       }
-    \int_set:Nn \l_@@_repeat_int
+    \int_gset:Nn \g_@@_repeat_int
       {
         \int_max:nn { 1 }
-          { \l_@@_duration_int * \l_@@_repeat_int / ( \l_@@_time_int * 4 ) }
+          {
+            \g_@@_duration_int * \g_@@_repeat_int
+            / ( \g_@@_time_int * 4 )
+          }
       }
-    \int_compare:nNnTF \l_@@_repeat_int = 1
-      { \int_set_eq:NN \l_@@_time_a_int \l_@@_time_int }
-      { \@@_run:N \l_@@_time_a_int }
-    \@@_run:N \l_@@_time_b_int
-    \@@_run:N \l_@@_time_c_int
-    \@@_run:N \l_@@_time_d_int
+    \int_compare:nNnTF \g_@@_repeat_int = 1
+      { \int_gset_eq:NN \g_@@_time_a_int \g_@@_time_int }
+      { \@@_run:N \g_@@_time_a_int }
+    \@@_run:N \g_@@_time_b_int
+    \@@_run:N \g_@@_time_c_int
+    \@@_run:N \g_@@_time_d_int
     \@@_set_median:
     \prg_break_point:
     \fp_gset:Nn \g_benchmark_time_fp
-      { \l_@@_time_median_int / \l_@@_repeat_int / 65536 }
+      { \g_@@_time_median_int / \g_@@_repeat_int / 65536 }
   }
 \cs_new_protected:Npn \@@_run:N
-  { \exp_args:NNo \@@_raw_replicate:nnN \l_@@_repeat_int { \g_@@_code_tl } }
+  { \exp_args:NNo \@@_raw_replicate:nnN \g_@@_repeat_int { \g_@@_code_tl } }
 %    \end{macrocode}
 % \end{macro}
 %
diff --git a/l3trial/l3benchmark/testfiles/m3benchmark000.tlg b/l3trial/l3benchmark/testfiles/m3benchmark000.tlg
index 49df45b..4a649a3 100644
--- a/l3trial/l3benchmark/testfiles/m3benchmark000.tlg
+++ b/l3trial/l3benchmark/testfiles/m3benchmark000.tlg
@@ -2,14 +2,14 @@ This is a generated file for the LaTeX (2e + expl3) validation system.
 Don't change this file in any respect.
 (l3benchmark.sty
 Package: l3benchmark YYYY-MM-DD L3 Experimental benchmarking
-\l__benchmark_duration_int=\count...
-\l__benchmark_time_int=\count...
-\l__benchmark_time_a_int=\count...
-\l__benchmark_time_b_int=\count...
-\l__benchmark_time_c_int=\count...
-\l__benchmark_time_d_int=\count...
-\l__benchmark_time_median_int=\count...
-\l__benchmark_repeat_int=\count...
+\g__benchmark_duration_int=\count...
+\g__benchmark_time_int=\count...
+\g__benchmark_time_a_int=\count...
+\g__benchmark_time_b_int=\count...
+\g__benchmark_time_c_int=\count...
+\g__benchmark_time_d_int=\count...
+\g__benchmark_time_median_int=\count...
+\g__benchmark_repeat_int=\count...
 \g__benchmark_nesting_int=\count...
 \g__benchmark_tictoc_int=\count...
 )
diff --git a/l3trial/l3benchmark/testfiles/m3benchmark001.lvt b/l3trial/l3benchmark/testfiles/m3benchmark001.lvt
index c51e064..2d0e013 100644
--- a/l3trial/l3benchmark/testfiles/m3benchmark001.lvt
+++ b/l3trial/l3benchmark/testfiles/m3benchmark001.lvt
@@ -23,8 +23,7 @@
     \END
   }
 
-\int_if_exist:NT \l__benchmark_duration_int
-  { \int_set:Nn \l__benchmark_duration_int { 65536 / 10 } }
+\fp_gset:Nn \g_benchmark_duration_target_fp { 0.01 }
 
 \OMIT
 \exp_args:NNx \seq_set_from_clist:Nn \l_tmpa_seq





More information about the latex3-commits mailing list