summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty')
-rw-r--r--Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty96
1 files changed, 24 insertions, 72 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty b/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty
index 113dfeaf344..828d0c4c4d8 100644
--- a/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty
+++ b/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty
@@ -20,67 +20,8 @@
%%
%% File: l3benchmark.dtx
\RequirePackage{expl3}
-\ProvidesExplPackage{l3benchmark}{2021-02-18}{}
+\ProvidesExplPackage{l3benchmark}{2021-05-27}{}
{L3 Experimental benchmarking}
-\sys_if_engine_luatex:TF
- {
- \cs_new:Npn \__sys_elapsedtime: { }
- \cs_new:Npn \__sys_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'__sys_elapsedtime:'
- lua.get_functions_table()[id] = function()
- write(tointeger((gettimeofday() - epoch)*65536 // 1))
- end~
- token.set_lua('__sys_elapsedtime:', id, 'global')
- id = luatexbase.new_luafunction'__sys_resettimer:'
- lua.get_functions_table()[id] = function()
- epoch = gettimeofday()
- end~
- token.set_lua('__sys_resettimer:', id, 'global', 'protected')
- }
- \cs_new:Npn \sys_timer:
- { \__sys_elapsedtime: }
- }
- {
- \cs_if_exist:NT \tex_elapsedtime:D
- {
- \cs_new:Npn \sys_timer:
- { \int_value:w \tex_elapsedtime:D }
- }
- }
-\__sys_const:nn { sys_if_timer_exist }
- { \cs_if_exist_p:N \sys_timer: }
-\cs_if_exist:NTF \sys_timer:
- {
- \sys_if_engine_luatex:TF
- {
- \cs_new_protected:Npn \sys_gzero_timer:
- { \__sys_resettimer: }
- }
- { \cs_new_protected:Npn \sys_gzero_timer: { \tex_resettimer:D } }
- }
- {
- \__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
- }
- }
\fp_new:N \g_benchmark_duration_target_fp
\fp_gset:Nn \g_benchmark_duration_target_fp { 1 }
\sys_if_timer_exist:F
@@ -89,6 +30,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:
@@ -147,8 +90,8 @@
\int_gset:Nn #3 { #1 - \g__benchmark_time_int }
\cs_set_eq:NN \__benchmark_tmp:w \prg_do_nothing:
}
-\fp_new:N \g__benchmark_time_fp
-\fp_new:N \g__benchmark_ops_fp
+\fp_new:N \g_benchmark_time_fp
+\fp_new:N \g_benchmark_ops_fp
\int_new:N \g__benchmark_duration_int
\int_new:N \g__benchmark_time_int
\int_new:N \g__benchmark_time_a_int
@@ -159,17 +102,27 @@
\tl_new:N \g__benchmark_code_tl
\cs_new_protected:Npn \benchmark_once:n #1
{
+ \benchmark_once_silent:n {#1}
+ \__benchmark_display:
+ }
+\cs_new_protected:Npn \benchmark_once_silent:n #1
+ {
\__benchmark_measure_op:
\__benchmark_raw:nN {#1} \g__benchmark_time_int
- \fp_gset:Nn \g__benchmark_time_fp { \g__benchmark_time_int / 65536 }
- \__benchmark_display:
+ \fp_gset:Nn \g_benchmark_time_fp { \g__benchmark_time_int / 65536 }
+ \fp_gset:Nn \g_benchmark_ops_fp { \g_benchmark_time_fp / \g__benchmark_one_op_fp }
}
\cs_new_protected:Npn \benchmark:n #1
{
+ \benchmark_silent:n {#1}
+ \__benchmark_display:
+ }
+\cs_new_protected:Npn \benchmark_silent:n #1
+ {
\__benchmark_measure_op:
\tl_gset:Nn \g__benchmark_code_tl {#1}
\__benchmark_aux:
- \__benchmark_display:
+ \fp_gset:Nn \g_benchmark_ops_fp { \g_benchmark_time_fp / \g__benchmark_one_op_fp }
}
\cs_new_protected:Npn \__benchmark_aux:
{
@@ -209,7 +162,7 @@
}
\prg_break_point:
\int_compare:nNnT \g__benchmark_time_int < 3 { \int_gzero:N \g__benchmark_time_int }
- \fp_gset:Nn \g__benchmark_time_fp
+ \fp_gset:Nn \g_benchmark_time_fp
{ \g__benchmark_time_int / \g__benchmark_repeat_int / 65536 }
}
\cs_new_protected:Npn \__benchmark_run:N
@@ -222,7 +175,7 @@
\tl_gset:Nn \g__benchmark_code_tl
{ \int_gadd:Nn \g__benchmark_duration_int { 0 } }
\__benchmark_aux:
- \fp_gset:Nn \g__benchmark_one_op_fp { max(\g__benchmark_time_fp, 1e-16) }
+ \fp_gset:Nn \g__benchmark_one_op_fp { max(\g_benchmark_time_fp, 1e-16) }
\int_gset:Nn \g__benchmark_duration_int
{ \fp_to_int:n { 65536 * \g_benchmark_duration_target_fp } }
}
@@ -239,11 +192,10 @@
{ \fp_to_tl:n { round(#2 * 1e-#1, 2) } e#1 }
\cs_new_protected:Npn \__benchmark_display:
{
- \fp_gset:Nn \g__benchmark_ops_fp { \g__benchmark_time_fp / \g__benchmark_one_op_fp }
\iow_term:x
{
- \__benchmark_fp_to_tl:N \g__benchmark_time_fp \c_space_tl seconds \c_space_tl
- ( \__benchmark_fp_to_tl:N \g__benchmark_ops_fp \c_space_tl ops)
+ \__benchmark_fp_to_tl:N \g_benchmark_time_fp \c_space_tl seconds \c_space_tl
+ ( \__benchmark_fp_to_tl:N \g_benchmark_ops_fp \c_space_tl ops)
}
}
\int_new:N \g__benchmark_tictoc_int
@@ -269,13 +221,13 @@
\cs_new_protected:Npn \__benchmark_toc:
{
\int_gdecr:N \g__benchmark_tictoc_int
- \fp_gset:Nn \g__benchmark_time_fp
+ \fp_gset:Nn \g_benchmark_time_fp
{ ( \sys_timer: - \l__benchmark_tictoc_pop_tl ) / 65536 }
\iow_term:x
{
\__benchmark_tictoc_prefix:
TOC: \c_space_tl
- \__benchmark_fp_to_tl:N \g__benchmark_time_fp \c_space_tl s
+ \__benchmark_fp_to_tl:N \g_benchmark_time_fp \c_space_tl s
}
}
\msg_new:nnn { benchmark } { toc-first }