[latex3-commits] [git/latex3] master: add tic/toc to l3benchmark (5fd85b9)
Will Robertson
wspr81 at gmail.com
Thu Jan 4 07:06:17 CET 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/5fd85b98ee36192212797e6c26fc9f13a2a4658b
>---------------------------------------------------------------
commit 5fd85b98ee36192212797e6c26fc9f13a2a4658b
Author: Will Robertson <wspr81 at gmail.com>
Date: Thu Jan 4 14:06:17 2018 +0800
add tic/toc to l3benchmark
are we going to release this package? I like it. (Although I wonder if the \clock: stuff should be in l3kernel.)
>---------------------------------------------------------------
5fd85b98ee36192212797e6c26fc9f13a2a4658b
l3trial/l3benchmark/l3benchmark.dtx | 82 +++++++++++++++++++++++++++++++++++
1 file changed, 82 insertions(+)
diff --git a/l3trial/l3benchmark/l3benchmark.dtx b/l3trial/l3benchmark/l3benchmark.dtx
index 96778f6..4b1bcfa 100644
--- a/l3trial/l3benchmark/l3benchmark.dtx
+++ b/l3trial/l3benchmark/l3benchmark.dtx
@@ -103,6 +103,20 @@
% \cs{l_benchmark_duration_fp} seconds.
% \end{variable}
%
+% \begin{function}{\benchmark_tic:,\benchmark_toc:}
+% \begin{syntax}
+% |\benchmark_tic:| \meta{slow code} |\benchmark_toc:|
+% \end{syntax}
+% When it is not possible to run \cs{benchmark:n} (e.g., the code
+% is part of the execution of a package which cannot be looped)
+% the tic/toc commands can be used instead to time between two points
+% in the code.
+% When executed, |\benchmark_tic:| will print a line to the terminal,
+% and |\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.
+% \end{function}
+%
% \end{documentation}
%
% \begin{implementation}
@@ -487,6 +501,74 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\benchmark_tic:}
+% \begin{macrocode}
+\int_new:N \g_tictoc_int
+\seq_new:N \g_tictoc_seq
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \benchmark_tic:
+ {
+ \int_compare:nTF { \g_tictoc_int == 0 }
+ {
+ \clock_zero:
+ \tl_set:Nn \l_tictoc_pop_tl {0}
+ }
+ {
+ \clock_get:N \l_tictoc_pop_tl
+ }
+
+ \seq_put_right:NV \g_tictoc_seq \l_tictoc_pop_tl
+ \int_gincr:N \g_tictoc_int
+
+ \iow_term:x
+ {
+ \prg_replicate:nn {\g_tictoc_int} {---+} \space
+ TIC
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\benchmark_toc:}
+% \begin{macrocode}
+\cs_set: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
+ \clock_get:N \l_tictoc_curr_tl
+
+ \tl_set:Nx \l_tictoc_tl
+ {
+ \fp_to_decimal:n
+ { round( \l_tictoc_curr_tl - \l_tictoc_pop_tl , 3 )}
+ }
+
+ \iow_term:x
+ {
+ \prg_replicate:nn {\g_tictoc_int} {---+} \space
+ TOC: \space
+ \l_tictoc_tl \space s
+ }
+
+ \int_gdecr:N \g_tictoc_int
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnn {benchmark} {toc-first}
+ {
+ \token_to_str:N \benchmark_toc: \space without~
+ \token_to_str:N \benchmark_tic: \space !
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}
More information about the latex3-commits
mailing list