diff options
author | Karl Berry <karl@freefriends.org> | 2018-11-20 22:02:39 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-11-20 22:02:39 +0000 |
commit | b6f9a8150be60baacc19b5035f1e344d14d1582c (patch) | |
tree | 02b435f7462e170e5f491c222bb7523c377a6629 /Master/texmf-dist/tex/latex/l3experimental/l3benchmark | |
parent | 2b465ca87794c05f1793552a8608392027a2e100 (diff) |
l3 (20nov18)
git-svn-id: svn://tug.org/texlive/trunk@49205 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/l3experimental/l3benchmark')
-rw-r--r-- | Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty | 205 |
1 files changed, 85 insertions, 120 deletions
diff --git a/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty b/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty index f9ed7d0c25c..87c8790e3d3 100644 --- a/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty +++ b/Master/texmf-dist/tex/latex/l3experimental/l3benchmark/l3benchmark.sty @@ -20,7 +20,7 @@ %% %% File: l3benchmark.dtx Copyright (C) 2011,2012,2014-2018 The LaTeX3 Project \RequirePackage{expl3} -\ProvidesExplPackage{l3benchmark}{2018-10-31}{} +\ProvidesExplPackage{l3benchmark}{2018-11-19}{} {L3 Experimental benchmarking} \sys_if_engine_luatex:TF { @@ -62,57 +62,22 @@ \c_zero_int } } -\fp_new:N \g_benchmark_time_fp -\fp_new:N \g_benchmark_ops_fp -\cs_new_protected:Npn \benchmark_display: - { \iow_term:x { \fp_to_tl:N \g_benchmark_time_fp \c_space_tl seconds } } -\cs_new_protected:Npn \benchmark_display_in_ops: - { - \iow_term:x - { - \fp_compare:nTF { \g_benchmark_ops_fp > 1e9 } - { \fp_to_tl:n { \g_benchmark_ops_fp * 1e-9 } ~ G~ops } - { - \fp_compare:nTF { \g_benchmark_ops_fp > 1e6 } - { \fp_to_tl:n { \g_benchmark_ops_fp * 1e-6 } ~ M~ops } - { - \fp_compare:nTF { \g_benchmark_ops_fp > 1e3 } - { \fp_to_tl:n { \g_benchmark_ops_fp * 1e-3 } ~ K~ops } - { \fp_to_tl:n { \g_benchmark_ops_fp } ~ ops } - } - } - } - } +\fp_new:N \g_benchmark_duration_target_fp +\fp_gset:Nn \g_benchmark_duration_target_fp { 1 } \sys_if_timer_exist:F { - \msg_new:nnnn { benchmark } { no-time } - { The~l3benchmark~package~failed~to~access~a~clock. } - { The~current~engine~provides~no~way~to~access~the~system~time. } + \fp_gset:Nn \g_benchmark_duration_target_fp { nan } \cs_new_protected:Npn \benchmark_once:n #1 { \msg_error:nn { benchmark } { no-time } } - \cs_new_protected:Npn \benchmark_once_in_ops:n #1 - { \msg_error:nn { benchmark } { no-time } } - \cs_new_protected:Npn \benchmark_once_silent:n #1 - { \msg_error:nn { benchmark } { no-time } } - \cs_new_protected:Npn \benchmark:n #1 - { \msg_error:nn { benchmark } { no-time } } - \cs_new_protected:Npn \benchmark_in_ops:n #1 + \cs_new_eq:NN \benchmark:n \benchmark_once:n + \cs_new_protected:Npn \benchmark_tic: { \msg_error:nn { benchmark } { no-time } } - \cs_new_protected:Npn \benchmark_silent:n #1 - { \msg_error:nn { benchmark } { no-time } } - \fp_gset:Nn \g_benchmark_time_fp { nan } - \fp_gset:Nn \g_benchmark_ops_fp { nan } + \cs_new_eq:NN \benchmark_toc: \benchmark_tic: + \msg_new:nnnn { benchmark } { no-time } + { The~l3benchmark~package~failed~to~access~a~clock. } + { The~current~engine~provides~no~way~to~access~the~system~time. } \msg_critical:nn { benchmark } { no-time } } -\fp_new:N \g_benchmark_duration_target_fp -\fp_gset:Nn \g_benchmark_duration_target_fp { 1 } -\int_new:N \g__benchmark_duration_int -\int_new:N \g__benchmark_time_int -\int_new:N \g__benchmark_time_a_int -\int_new:N \g__benchmark_time_b_int -\int_new:N \g__benchmark_time_c_int -\int_new:N \g__benchmark_time_d_int -\int_new:N \g__benchmark_repeat_int \int_new:N \g__benchmark_nesting_int \cs_new_protected:Npn \__benchmark_raw:nN #1 { @@ -163,63 +128,52 @@ \int_gset:Nn #3 { #1 - \g__benchmark_time_int } \cs_set_eq:NN \__benchmark_tmp:w \prg_do_nothing: } -\fp_new:N \g__benchmark_one_op_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 +\int_new:N \g__benchmark_time_b_int +\int_new:N \g__benchmark_time_c_int +\int_new:N \g__benchmark_time_d_int +\int_new:N \g__benchmark_repeat_int \tl_new:N \g__benchmark_code_tl -\cs_new_protected:Npn \benchmark:n #1 - { \benchmark_silent:n {#1} \benchmark_display: } -\cs_new_protected:Npn \benchmark_in_ops:n #1 - { \benchmark_silent:n {#1} \benchmark_display_in_ops: } -\cs_new_protected:Npn \__benchmark_measure_op: +\cs_new_protected:Npn \benchmark_once:n #1 { - \int_gset:Nn \g__benchmark_duration_int { 256 } - \tl_gset:Nn \g__benchmark_code_tl - { \int_gset:Nn \g__benchmark_duration_int { 256 } } % arbitrary single operation - \__benchmark_aux: - \fp_gset_eq:NN \g__benchmark_one_op_fp \g_benchmark_time_fp - \fp_compare:nNnT \g__benchmark_one_op_fp < { 1e-6 } - { \fp_gset:Nn \g__benchmark_one_op_fp { 1e-6 } } + \__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: } -\cs_new_protected:Npn \benchmark_silent:n #1 +\cs_new_protected:Npn \benchmark:n #1 { \__benchmark_measure_op: - \int_gset:Nn \g__benchmark_duration_int - { \fp_to_int:n { 65536 * \g_benchmark_duration_target_fp } } \tl_gset:Nn \g__benchmark_code_tl {#1} \__benchmark_aux: - \fp_gset:Nn \g_benchmark_ops_fp - { \g_benchmark_time_fp / \g__benchmark_one_op_fp } + \__benchmark_display: } \cs_new_protected:Npn \__benchmark_aux: { \int_gset:Nn \g__benchmark_repeat_int { 1 } \__benchmark_raw:nN { \g__benchmark_code_tl } \g__benchmark_time_int \int_compare:nNnF \g__benchmark_time_int < { \g__benchmark_duration_int / 2 } + { \prg_break: } + \bool_until_do:nn { - \int_gset_eq:NN \g__benchmark_time_a_int \g__benchmark_time_int - \int_gset_eq:NN \g__benchmark_time_b_int \g__benchmark_time_int - \int_gset_eq:NN \g__benchmark_time_c_int \g__benchmark_time_int - \int_gset_eq:NN \g__benchmark_time_d_int \g__benchmark_time_int - \prg_break: + \int_compare_p:nNn \g__benchmark_time_int > { \g__benchmark_duration_int / 32 } + || \int_compare_p:nNn \g__benchmark_repeat_int > { \c_max_int / 4 } } - \int_while_do:nNnn \g__benchmark_time_int < { \g__benchmark_duration_int / 100 } { - \int_compare:nNnT \g__benchmark_repeat_int > { \c_max_int / 4 } - { - \int_gzero:N \g__benchmark_time_a_int - \int_gzero:N \g__benchmark_time_b_int - \int_gzero:N \g__benchmark_time_c_int - \int_gzero:N \g__benchmark_time_d_int - \prg_break: - } \int_gset:Nn \g__benchmark_repeat_int { 4 * \g__benchmark_repeat_int } \__benchmark_run:N \g__benchmark_time_int } \int_gset:Nn \g__benchmark_repeat_int { - \int_max:nn { 1 } + \fp_to_int:n { - \g__benchmark_duration_int * \g__benchmark_repeat_int - / ( \g__benchmark_time_int * 4 ) + max ( 1 , min ( \c_max_int , + \g__benchmark_duration_int * \g__benchmark_repeat_int / + \int_eval:n { 4 * \g__benchmark_time_int } ) ) } } \int_compare:nNnTF \g__benchmark_repeat_int = 1 @@ -228,76 +182,87 @@ \__benchmark_run:N \g__benchmark_time_b_int \__benchmark_run:N \g__benchmark_time_c_int \__benchmark_run:N \g__benchmark_time_d_int - \prg_break_point: - \fp_gset:Nn \g_benchmark_time_fp + \int_gset:Nn \g__benchmark_time_int { \int_min:nn { \int_min:nn \g__benchmark_time_a_int \g__benchmark_time_b_int } { \int_min:nn \g__benchmark_time_c_int \g__benchmark_time_d_int } - / \g__benchmark_repeat_int / 65536 } + \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 + { \g__benchmark_time_int / \g__benchmark_repeat_int / 65536 } } \cs_new_protected:Npn \__benchmark_run:N { \exp_args:NNo \__benchmark_raw_replicate:nnN \g__benchmark_repeat_int { \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_in_ops:n #1 - { \benchmark_once_silent:n {#1} \benchmark_display_in_ops: } -\cs_new_protected:Npn \benchmark_once_silent:n #1 +\fp_new:N \g__benchmark_one_op_fp +\cs_new_protected:Npn \__benchmark_measure_op: { - \__benchmark_measure_op: - \__benchmark_raw:nN {#1} \g__benchmark_time_int - \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 } + \int_gset:Nn \g__benchmark_duration_int + { \fp_to_int:n { 65536 * \g_benchmark_duration_target_fp } / 4 } + \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) } + \int_gset:Nn \g__benchmark_duration_int + { \fp_to_int:n { 65536 * \g_benchmark_duration_target_fp } } } -\int_new:N \g__benchmark_tictoc_int -\seq_new:N \g__benchmark_tictoc_seq -\cs_new_protected:Npn \benchmark_tic: +\cs_new:Npn \__benchmark_fp_to_tl:N #1 { - \int_compare:nTF { \g__benchmark_tictoc_int == 0 } + \fp_compare:nTF { abs(#1) < 1000 } + { \fp_to_tl:n { round(#1, 2 - logb(#1)) } } { - \sys_gzero_timer: - \__benchmark_tic: + \exp_args:Nf \__benchmark_fp_to_tl_aux:nN + { \fp_to_int:n { logb(#1) } } #1 } - { \__benchmark_tic: } } -\cs_new_protected:Npn \__benchmark_tic: +\cs_new:Npn \__benchmark_fp_to_tl_aux:nN #1#2 + { \fp_to_tl:n { round(#2 * 1e-#1, 2) } e#1 } +\cs_new_protected:Npn \__benchmark_display: { - \exp_args:NNf \seq_put_right:Nn \g__benchmark_tictoc_seq { \sys_timer: } - \int_gincr:N \g__benchmark_tictoc_int + \fp_gset:Nn \g__benchmark_ops_fp { \g__benchmark_time_fp / \g__benchmark_one_op_fp } \iow_term:x { - \prg_replicate:nn {\g__benchmark_tictoc_int} {---+} \space - TIC + \__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 +\seq_new:N \g__benchmark_tictoc_seq +\tl_new:N \l__benchmark_tictoc_pop_tl +\cs_new:Npn \__benchmark_tictoc_prefix: + { + (l3benchmark) \c_space_tl + + \prg_replicate:nn { \g__benchmark_tictoc_int } { -+ } \c_space_tl + } +\cs_new_protected:Npn \benchmark_tic: + { + \iow_term:x { \__benchmark_tictoc_prefix: TIC } + \exp_args:NNf \seq_gput_right:Nn \g__benchmark_tictoc_seq { \sys_timer: } + \int_gincr:N \g__benchmark_tictoc_int + } \cs_new:Npn \benchmark_toc: { - \int_compare:nT { \g__benchmark_tictoc_int == 0 } - { \msg_error:nn {benchmark} {toc-first} } - \seq_pop_right:NN \g__benchmark_tictoc_seq \l__benchmark_tictoc_pop_tl - \__benchmark_toc: + \seq_gpop_right:NNTF \g__benchmark_tictoc_seq \l__benchmark_tictoc_pop_tl + { \__benchmark_toc: } + { \msg_error:nn { benchmark } { toc-first } } } \cs_new_protected:Npn \__benchmark_toc: { - \tl_set:Nx \l__benchmark_tictoc_tl - { - \fp_to_decimal:n - { round( ( \sys_timer: - \l__benchmark_tictoc_pop_tl) / 65536 , 3 ) } - } + \int_gdecr:N \g__benchmark_tictoc_int + \fp_gset:Nn \g__benchmark_time_fp + { ( \sys_timer: - \l__benchmark_tictoc_pop_tl ) / 65536 } \iow_term:x { - \prg_replicate:nn {\g__benchmark_tictoc_int} {---+} \c_space_tl + \__benchmark_tictoc_prefix: TOC: \c_space_tl - \l__benchmark_tictoc_tl \c_space_tl s + \__benchmark_fp_to_tl:N \g__benchmark_time_fp \c_space_tl s } - \int_gdecr:N \g__benchmark_tictoc_int } -\msg_new:nnn {benchmark} {toc-first} +\msg_new:nnn { benchmark } { toc-first } { - \token_to_str:N \benchmark_toc: \space without~ - \token_to_str:N \benchmark_tic: \space ! + \token_to_str:N \benchmark_toc: \c_space_tl without~ + \token_to_str:N \benchmark_tic: \c_space_tl ! } %% %% |