diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3experimental/l3benchmark/l3benchmark.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3experimental/l3benchmark/l3benchmark.dtx | 177 |
1 files changed, 48 insertions, 129 deletions
diff --git a/Master/texmf-dist/source/latex/l3experimental/l3benchmark/l3benchmark.dtx b/Master/texmf-dist/source/latex/l3experimental/l3benchmark/l3benchmark.dtx index 1771ac26668..3cb4fa08804 100644 --- a/Master/texmf-dist/source/latex/l3experimental/l3benchmark/l3benchmark.dtx +++ b/Master/texmf-dist/source/latex/l3experimental/l3benchmark/l3benchmark.dtx @@ -46,32 +46,12 @@ % }^^A % } % -% \date{Released 2021-02-18} +% \date{Released 2021-05-27} % % \maketitle % % \begin{documentation} % -% \section{Additions to \pkg{l3sys}: elapsed time} -% -% \begin{function}{\sys_gzero_timer:} -% \begin{syntax} -% \cs{sys_gzero_timer:} -% \end{syntax} -% Resets the timer to zero. -% \end{function} -% -% \begin{function}[EXP]{\sys_timer:} -% \begin{syntax} -% \cs{sys_timer:} -% \end{syntax} -% Expands to the current value of the engine's timer clock, a -% non-negative integer. In engines without clock support this expands -% to $0$ after an error. In \LuaTeX{} only the CPU time is measured, -% while in other engines real time is measured (including time waiting -% for user input). -% \end{function} -% % \section{Benchmark} % % \begin{variable}{\g_benchmark_duration_target_fp} @@ -83,22 +63,35 @@ % than this. % \end{variable} % -% \begin{function}{\benchmark_once:n} +% \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 in seconds, 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, \benchmark_once_silent:n} % \begin{syntax} +% \cs{benchmark_once_silent:n} \Arg{code} % \cs{benchmark_once:n} \Arg{code} % \end{syntax} -% Prints to the terminal the time taken by \TeX{} to run the -% \meta{code}, and an estimated number of elementary operations. The +% Determines the time \cs{g_benchmark_time_fp} (in seconds) taken by +% \TeX{} to run the \meta{code}, and an estimated number +% \cs{g_benchmark_ops_fp} of elementary operations. In addition, +% \cs{benchmark_once:n} prints these values to the terminal. The % \meta{code} is run only once so the time may be quite inaccurate for % fast code. % \end{function} % -% \begin{function}{\benchmark:n} +% \begin{function}{\benchmark:n, \benchmark_silent:n} % \begin{syntax} % \cs{benchmark:n} \Arg{code} % \end{syntax} -% Prints to the terminal the time taken by \TeX{} to run the -% \meta{code}, and an estimated number of elementary operations. The +% Determines the time \cs{g_benchmark_time_fp} (in seconds) taken by +% \TeX{} to run the \meta{code}, and an estimated number +% \cs{g_benchmark_ops_fp} of elementary operations. In addition, +% \cs{benchmark:n} prints these values to the terminal. The % \meta{code} may be run many times and not within a group, thus code % with side-effects may cause problems. % \end{function} @@ -129,95 +122,10 @@ % \end{macrocode} % % \begin{macrocode} -\ProvidesExplPackage{l3benchmark}{2021-02-18}{} +\ProvidesExplPackage{l3benchmark}{2021-05-27}{} {L3 Experimental benchmarking} % \end{macrocode} % -% \subsection{Additions to \pkg{l3sys}: elapsed time} -% -% \begin{macrocode} -%<@@=sys> -% \end{macrocode} -% -% \begin{macro}[EXP]{\sys_timer:, \@@_elapsedtime:, \@@_resettimer:} -% \begin{macro}[EXP,pTF]{\sys_if_timer_exist:} -% In \LuaTeX{}, use emulation (see \pkg{l3luatex}), -% otherwise try to locate the primitive. The -% elapsed time will be available if this succeeds. -% \begin{macrocode} -\sys_if_engine_luatex:TF - { - \cs_new:Npn \@@_elapsedtime: { } - \cs_new:Npn \@@_resettimer: { } - \lua_now:n - { - local~gettimeofday = os.gettimeofday~ - local~epoch = gettimeofday() - os.clock()~ - local~write = tex.write~ - local~tointeger = math.tointeger~ - local~id = luatexbase.new_luafunction'@@_elapsedtime:' - lua.get_functions_table()[id] = function() - write(tointeger((gettimeofday() - epoch)*65536 // 1)) - end~ - token.set_lua('@@_elapsedtime:', id, 'global') - id = luatexbase.new_luafunction'@@_resettimer:' - lua.get_functions_table()[id] = function() - epoch = gettimeofday() - end~ - token.set_lua('@@_resettimer:', id, 'global', 'protected') - } - \cs_new:Npn \sys_timer: - { \@@_elapsedtime: } - } - { - \cs_if_exist:NT \tex_elapsedtime:D - { - \cs_new:Npn \sys_timer: - { \int_value:w \tex_elapsedtime:D } - } - } -\@@_const:nn { sys_if_timer_exist } - { \cs_if_exist_p:N \sys_timer: } -% \end{macrocode} -% \end{macro} -% \end{macro} -% -% \begin{macro}{\sys_gzero_timer:} -% Three case, and in each case we define \cs{sys_gzero_timer:}. -% \begin{macrocode} -\cs_if_exist:NTF \sys_timer: - { - \sys_if_engine_luatex:TF - { - \cs_new_protected:Npn \sys_gzero_timer: - { \@@_resettimer: } - } - { \cs_new_protected:Npn \sys_gzero_timer: { \tex_resettimer:D } } - } -% \end{macrocode} -% If the elapsed time cannot be accessed then we define user -% commands to produce errors. -% \begin{macrocode} - { - \__kernel_msg_new:nnnn { kernel } { no-elapsed-time } - { No~clock~detected~for~#1. } - { The~current~engine~provides~no~way~to~access~the~system~time. } - \cs_new_protected:Npn \sys_gzero_timer: - { - \__kernel_msg_error:nnn { kernel } { no-elapsed-time } - { \sys_gzero_timer: } - } - \cs_new:Npn \sys_timer: - { - \int_value:w - \__kernel_msg_expandable_error:nnn { kernel } { no-elapsed-time } - { \sys_timer: } - \c_zero_int - } - } -% \end{macrocode} -% \end{macro} -% % \subsection{Benchmarking code} % % \begin{macrocode} @@ -242,6 +150,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: @@ -337,13 +247,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} % @@ -381,7 +291,7 @@ % \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 @@ -389,10 +299,15 @@ % \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} @@ -402,10 +317,15 @@ % \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} @@ -460,7 +380,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 @@ -488,7 +408,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 } } } @@ -519,11 +439,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} @@ -573,13 +492,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 } |