[latex3-commits] [git/LaTeX3-latex3-latex3] master: Implement \benchmark_apply:nN, perhaps should remain internal (619ec7e)
Bruno Le Floch
bruno at le-floch.fr
Wed May 9 00:11:20 CEST 2018
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/619ec7ea2365e4699411d36f0889c62ffb0dab22
>---------------------------------------------------------------
commit 619ec7ea2365e4699411d36f0889c62ffb0dab22
Author: Bruno Le Floch <bruno at le-floch.fr>
Date: Tue May 8 18:11:20 2018 -0400
Implement \benchmark_apply:nN, perhaps should remain internal
>---------------------------------------------------------------
619ec7ea2365e4699411d36f0889c62ffb0dab22
l3trial/l3benchmark/l3benchmark.dtx | 34 +++++++---
l3trial/l3benchmark/testfiles/m3benchmark001.lvt | 27 +++++---
.../l3benchmark/testfiles/m3benchmark001.xetex.tlg | 71 +-------------------
3 files changed, 46 insertions(+), 86 deletions(-)
diff --git a/l3trial/l3benchmark/l3benchmark.dtx b/l3trial/l3benchmark/l3benchmark.dtx
index 3bdc901..ebd9bfa 100644
--- a/l3trial/l3benchmark/l3benchmark.dtx
+++ b/l3trial/l3benchmark/l3benchmark.dtx
@@ -91,28 +91,34 @@
% \cs{benchmark_display:n} \Arg{time}
% \end{syntax}
% Prints the \meta{time} (in seconds) to the terminal. This function
-% can be redefined.
+% can be redefined by the user.
% \end{function}
%
-% \begin{function}{\benchmark_once:n}
+% \begin{function}{\benchmark_once:n, \benchmark_once_apply:nN}
% \begin{syntax}
% \cs{benchmark_once:n} \Arg{code}
+% \cs{benchmark_once_apply:nN} \Arg{code} \Arg{function}
% \end{syntax}
% Measures the time taken by \TeX{} to run the \meta{code} once, and
% calls \cs{benchmark_display:n} \Arg{time} with the \meta{time} in
% seconds. The code is run only once so the time may be quite
-% inaccurate for fast code.
+% inaccurate for fast code. The \cs{benchmark_once_apply:nN} function
+% calls \meta{function} \Arg{time} instead of \cs{benchmark_display:n}
+% \Arg{time}.
% \end{function}
%
-% \begin{function}{\benchmark:n}
+% \begin{function}{\benchmark:n, \benchmark_apply:nN}
% \begin{syntax}
% \cs{benchmark:n} \Arg{code}
+% \cs{benchmark_apply:nN} \Arg{code} \meta{function}
% \end{syntax}
% Measures the time taken by \TeX{} to run the \meta{code}, and calls
% \cs{benchmark_display:n} \Arg{time} with the \meta{time} in seconds.
% This function cannot be nested. The \meta{code} may be run many
% times in a row, and not within a group, thus it should not have
-% side-effects.
+% side-effects. The \cs{benchmark_apply:nN} function calls
+% \meta{function} \Arg{time} instead of \cs{benchmark_display:n}
+% \Arg{time}.
% \end{function}
%
% \begin{function}{\benchmark_tic:,\benchmark_toc:}
@@ -317,9 +323,13 @@ end
Please~use~pdfTeX,~LuaTeX,~or~call~other~engines~with~the~
--shell-escape~option.
}
+ \cs_new_protected:Npn \benchmark_once:n #1
+ { \msg_error:nn { benchmark } { no-time } }
+ \cs_new_protected:Npn \benchmark_once_apply:nN #1#2
+ { \msg_error:nn { benchmark } { no-time } }
\cs_new_protected:Npn \benchmark:n #1
{ \msg_error:nn { benchmark } { no-time } }
- \cs_new_protected:Npn \benchmark_once:n #1
+ \cs_new_protected:Npn \benchmark_apply:nN #1#2
{ \msg_error:nn { benchmark } { no-time } }
\msg_critical:nn { benchmark } { no-time }
}
@@ -392,13 +402,15 @@ end
% \end{macro}
% \end{variable}
%
-% \begin{macro}{\benchmark_once:n}
+% \begin{macro}{\benchmark_once:n, \benchmark_once_apply:nN}
% Convert from scaled seconds to seconds.
% \begin{macrocode}
\cs_new_protected:Npn \benchmark_once:n #1
+ { \benchmark_once_apply:nN {#1} \benchmark_display:n }
+\cs_new_protected:Npn \benchmark_once_apply:nN #1#2
{
\@@_raw:nN {#1} \l_@@_time_int
- \benchmark_display:f { \fp_to_tl:n { \l_@@_time_int / 65536 } }
+ \exp_args:Nf #2 { \fp_to_tl:n { \l_@@_time_int / 65536 } }
}
% \end{macrocode}
% \end{macro}
@@ -467,7 +479,7 @@ end
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\benchmark:n}
+% \begin{macro}{\benchmark:n, \benchmark_apply:nN}
% The main timing function. First time the user code once. If that
% took more than a third of a second we're done. If that took much
% less than a second, quadruple the number of copies until it takes a
@@ -482,6 +494,8 @@ end
\tl_new:N \g_@@_code_tl
\fp_new:N \l_@@_time_fp
\cs_new_protected:Npn \benchmark:n #1
+ { \benchmark_apply:nN {#1} \benchmark_display:n }
+\cs_new_protected:Npn \benchmark_apply:nN #1#2
{
\int_set:Nn \l_@@_repeat_int { 1 }
\tl_gset:Nn \g_@@_code_tl {#1}
@@ -513,7 +527,7 @@ end
\prg_break_point:
\fp_set:Nn \l_@@_time_fp
{ \l_@@_time_median_int / \l_@@_repeat_int / 65536 }
- \benchmark_display:f { \fp_to_tl:N \l_@@_time_fp }
+ \exp_args:Nf #2 { \fp_to_tl:N \l_@@_time_fp }
}
\cs_new_protected:Npn \@@_run:N
{ \exp_args:NNo \@@_raw_replicate:nnN \l_@@_repeat_int { \g_@@_code_tl } }
diff --git a/l3trial/l3benchmark/testfiles/m3benchmark001.lvt b/l3trial/l3benchmark/testfiles/m3benchmark001.lvt
index afb15e9..c82ad2b 100644
--- a/l3trial/l3benchmark/testfiles/m3benchmark001.lvt
+++ b/l3trial/l3benchmark/testfiles/m3benchmark001.lvt
@@ -14,10 +14,23 @@
\START
\ExplSyntaxOn
+\sys_if_timer_exist:F
+ {
+ \benchmark_once:n \ERROR \TRUE
+ \benchmark_once_apply:nN \ERROR \ERROR \TRUE
+ \benchmark:n \ERROR \TRUE
+ \benchmark_apply:nN \ERROR \ERROR \TRUE
+ \END
+ }
+
\int_if_exist:NT \l__benchmark_duration_int
{ \int_set:Nn \l__benchmark_duration_int { 65536 / 10 } }
\OMIT
+\cs_new:Npn \test:nn #1#2 { #2 {#1} }
+\TIMO
+
+\OMIT
\exp_args:NNx \seq_set_from_clist:Nn \l_tmpa_seq
{ \prg_replicate:nn { 123 } { a , } }
\cs_new_protected:Npn \test_slow_code:
@@ -27,8 +40,8 @@
\TEST { benchmark_once }
{
\int_zero:N \l_tmpa_int
- \cs_gset_protected:Npn \benchmark_display:n { \fp_set:Nn \l_tmpa_fp }
- \benchmark_once:n { \int_incr:N \l_tmpa_int }
+ \benchmark_once_apply:nN { \int_incr:N \l_tmpa_int }
+ \test:nn { \fp_set:Nn \l_tmpa_fp }
\int_log:N \l_tmpa_int % Check the code was done only once
\fp_compare:nTF { \l_tmpa_fp < 5e-5 } % Check it took 0 to 3 scaled seconds
{ \TRUE }
@@ -41,12 +54,10 @@
\clist_clear:N \l_tmpb_clist
\prg_replicate:nn { 3 }
{
- \cs_gset_protected:Npn \benchmark_display:n
- { \clist_put_right:Nn \l_tmpa_clist }
- \benchmark:n { \test_slow_code: }
- \cs_gset_protected:Npn \benchmark_display:n
- { \clist_put_right:Nn \l_tmpb_clist }
- \benchmark:n { \test_slow_code: \test_slow_code: }
+ \benchmark_apply:nN { \test_slow_code: }
+ \test:nn { \clist_put_right:Nn \l_tmpa_clist }
+ \benchmark_apply:nN { \test_slow_code: \test_slow_code: }
+ \test:nn { \clist_put_right:Nn \l_tmpb_clist }
}
\fp_compare:nTF % Check that doing code twice takes between 1.5 and 2.5 times as much
{
diff --git a/l3trial/l3benchmark/testfiles/m3benchmark001.xetex.tlg b/l3trial/l3benchmark/testfiles/m3benchmark001.xetex.tlg
index b9fb8e5..8c2f095 100644
--- a/l3trial/l3benchmark/testfiles/m3benchmark001.xetex.tlg
+++ b/l3trial/l3benchmark/testfiles/m3benchmark001.xetex.tlg
@@ -1,8 +1,5 @@
This is a generated file for the LaTeX (2e + expl3) validation system.
Don't change this file in any respect.
-============================================================
-TEST 1: benchmark_once
-============================================================
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! benchmark error: "no-time"
@@ -19,60 +16,7 @@ l. ... }
| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
| call other engines with the --shell-escape option.
|...............................................
-> \l_tmpa_int=0.
TRUE
-============================================================
-============================================================
-TEST 2: benchmark
-============================================================
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! benchmark error: "no-time"
-!
-! The l3benchmark package failed to access a clock.
-!
-! See the benchmark documentation for further information.
-!
-! For immediate help type H <return>.
-!...............................................
-l. ... }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| The current engine provides no way to access the system time, hence making
-| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
-| call other engines with the --shell-escape option.
-|...............................................
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! benchmark error: "no-time"
-!
-! The l3benchmark package failed to access a clock.
-!
-! See the benchmark documentation for further information.
-!
-! For immediate help type H <return>.
-!...............................................
-l. ... }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| The current engine provides no way to access the system time, hence making
-| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
-| call other engines with the --shell-escape option.
-|...............................................
-!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-!
-! benchmark error: "no-time"
-!
-! The l3benchmark package failed to access a clock.
-!
-! See the benchmark documentation for further information.
-!
-! For immediate help type H <return>.
-!...............................................
-l. ... }
-|'''''''''''''''''''''''''''''''''''''''''''''''
-| The current engine provides no way to access the system time, hence making
-| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
-| call other engines with the --shell-escape option.
-|...............................................
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! benchmark error: "no-time"
@@ -89,6 +33,7 @@ l. ... }
| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
| call other engines with the --shell-escape option.
|...............................................
+TRUE
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! benchmark error: "no-time"
@@ -105,6 +50,7 @@ l. ... }
| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
| call other engines with the --shell-escape option.
|...............................................
+TRUE
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
! benchmark error: "no-time"
@@ -121,15 +67,4 @@ l. ... }
| benchmarking impossible without shell-escape. Please use pdfTeX, LuaTeX, or
| call other engines with the --shell-escape option.
|...............................................
-! Undefined control sequence.
-<argument> \ERROR
- \TYPE {1:\l_tmpa_clist }\TYPE {2:\l_tmpb_clist }
-l. ... }
-The control sequence at the end of the top line
-of your error message was never \def'ed. If you have
-misspelled it (e.g., `\hobx'), type `I' and the correct
-spelling (e.g., `I\hbox'). Otherwise just continue,
-and I'll forget about whatever was undefined.
-1:
-2:
-============================================================
+TRUE
More information about the latex3-commits
mailing list