What is the LaTeX equivalent of ConTeXt testfeatureonce to benchmark performance
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
ConTeXt provides a macro testfeatureonce
to benchmark performance. The syntax is
testfeatureoncen...
which runs the code in the second argument n
times (n
is assumed to be an integer) and stores the elapsed time (in seconds) in the macro elapasedtime
. The following diagnostic message is also printed on the terminal:
system > starting feature test (n=1)
system > 1 feature tests done (1.353s)
Here is a minimal ConTeXt document showing it's usage:
starttext
testfeatureonce1000
setbox0hbox
startMPcode draw (0,0) -- (1cm, 1cm); stopMPcode
elapsedtime
stoptext
What is the functionally equivalent macro in LaTeX used for benchmarking performance?
context performance
add a comment |Â
up vote
3
down vote
favorite
ConTeXt provides a macro testfeatureonce
to benchmark performance. The syntax is
testfeatureoncen...
which runs the code in the second argument n
times (n
is assumed to be an integer) and stores the elapsed time (in seconds) in the macro elapasedtime
. The following diagnostic message is also printed on the terminal:
system > starting feature test (n=1)
system > 1 feature tests done (1.353s)
Here is a minimal ConTeXt document showing it's usage:
starttext
testfeatureonce1000
setbox0hbox
startMPcode draw (0,0) -- (1cm, 1cm); stopMPcode
elapsedtime
stoptext
What is the functionally equivalent macro in LaTeX used for benchmarking performance?
context performance
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
ConTeXt provides a macro testfeatureonce
to benchmark performance. The syntax is
testfeatureoncen...
which runs the code in the second argument n
times (n
is assumed to be an integer) and stores the elapsed time (in seconds) in the macro elapasedtime
. The following diagnostic message is also printed on the terminal:
system > starting feature test (n=1)
system > 1 feature tests done (1.353s)
Here is a minimal ConTeXt document showing it's usage:
starttext
testfeatureonce1000
setbox0hbox
startMPcode draw (0,0) -- (1cm, 1cm); stopMPcode
elapsedtime
stoptext
What is the functionally equivalent macro in LaTeX used for benchmarking performance?
context performance
ConTeXt provides a macro testfeatureonce
to benchmark performance. The syntax is
testfeatureoncen...
which runs the code in the second argument n
times (n
is assumed to be an integer) and stores the elapsed time (in seconds) in the macro elapasedtime
. The following diagnostic message is also printed on the terminal:
system > starting feature test (n=1)
system > 1 feature tests done (1.353s)
Here is a minimal ConTeXt document showing it's usage:
starttext
testfeatureonce1000
setbox0hbox
startMPcode draw (0,0) -- (1cm, 1cm); stopMPcode
elapsedtime
stoptext
What is the functionally equivalent macro in LaTeX used for benchmarking performance?
context performance
context performance
asked 2 hours ago
Aditya
54.4k2108230
54.4k2108230
add a comment |Â
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
3
down vote
With pdfTeX you can simulate the behaviour using pdfresettimer
and pdfelapsedtime
. I used some expl3
wrappers to make the same syntax as the ConTeXt version.
documentclassarticle
usepackagexparse
usepackagetikz
%% For LuaTeX
% defpdfresettimerdirectluapdfelapsedtimer_basetime = os.clock()
% defpdfelapsedtimedirectluatex.print((os.clock()-pdfelapsedtimer_basetime)*65536)
%%
ExplSyntaxOn
cs_set_eq:NN __tfo_start_timer: pdfresettimer
cs_set_eq:NN __tfo_elapsed_time: pdfelapsedtime
cs_new:Npn __tfo_output:n #1
iow_term:x
>~#1~feature~tests~done~
(fp_eval:n round ( __tfo_elapsed_time: / 65536 , 3 ) s)
cs_new:Npn __tfo_run_n_times:nn #1 #2
if_int_compare:w #1 > 0 scan_stop:
exp_after:wN __tfo_run_n_times:nn
exp_after:wN int_value:w __int_eval:w #1 - 1 #2
fi:
NewDocumentCommandTestFeatureOnce
m m
__tfo_start_timer:
__tfo_run_n_times:nn #1 #2
__tfo_output:n #1
ExplSyntaxOff
begindocument
TestFeatureOnce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
enddocument
For LuaTeX I used the code from this post (which is also implemented in pdftexcmds
). However I used a slightly modified version that does not use a protecteddef
to allow the returned pdfelapsedtime
to be f
-expanded by l3fp
.
I don't know if this is possible in XeTeX without resorting to system commands...
add a comment |Â
up vote
2
down vote
For all I know, there's no such macro in the LaTeX2e base (perhaps LaTeX3 has something equivalent?). But we can look up the definition of testfeatureonce
in the ConTeXt source code. The relevant definitions are in the syst-aux
module.
That implementation makes use of the eTeX primitives pdfresettimer
and pdfelapsedtime
to reset an internal timer and get the elapsed time since the last reset, respectively. I didn't find a proper source for this, but it seems 65536 equals one second in the value returned by pdfelapsedtime
.
A reimplementation in pure LaTeX code might look like this:
documentclassarticle
usepackagetikz
makeatletter
letresettimer=pdfresettimer
letelapsedtime=pdfelapsedtime
newcountc@syst@helpers@test@feature@n
newcountc@syst@helpers@test@feature@m
newcommandtestfeature[2]%
c@syst@helpers@test@feature@m=#1relax
defsyst@helpers@test@feature@step%
advancec@syst@helpers@test@feature@n by 1relax
ifnumc@syst@helpers@test@feature@n>c@syst@helpers@test@feature@melse
#2expandaftersyst@helpers@test@feature@step
fi
%
retestfeature
newcommandretestfeature
bgroup
ifcaseinteractionmode letwaitrelax fi
resettimer
c@syst@helpers@test@feature@n=0relax
syst@helpers@test@feature@step
wait
egroup
newcommandtestfeatureonce[2]%
begingroup
letwaitrelax
testfeature#1#2%
endgroup
makeatother
begindocument
testfeatureonce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
theelapsedtime
enddocument
Thanks! I had looked at that definition but didn't realize that etex provides the primitivespdfresettimer
andpdfelapsedtime
.
â Aditya
45 mins ago
To make this solution work inluatex
, we need to follow the approach used in this answer
â Aditya
30 mins ago
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
With pdfTeX you can simulate the behaviour using pdfresettimer
and pdfelapsedtime
. I used some expl3
wrappers to make the same syntax as the ConTeXt version.
documentclassarticle
usepackagexparse
usepackagetikz
%% For LuaTeX
% defpdfresettimerdirectluapdfelapsedtimer_basetime = os.clock()
% defpdfelapsedtimedirectluatex.print((os.clock()-pdfelapsedtimer_basetime)*65536)
%%
ExplSyntaxOn
cs_set_eq:NN __tfo_start_timer: pdfresettimer
cs_set_eq:NN __tfo_elapsed_time: pdfelapsedtime
cs_new:Npn __tfo_output:n #1
iow_term:x
>~#1~feature~tests~done~
(fp_eval:n round ( __tfo_elapsed_time: / 65536 , 3 ) s)
cs_new:Npn __tfo_run_n_times:nn #1 #2
if_int_compare:w #1 > 0 scan_stop:
exp_after:wN __tfo_run_n_times:nn
exp_after:wN int_value:w __int_eval:w #1 - 1 #2
fi:
NewDocumentCommandTestFeatureOnce
m m
__tfo_start_timer:
__tfo_run_n_times:nn #1 #2
__tfo_output:n #1
ExplSyntaxOff
begindocument
TestFeatureOnce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
enddocument
For LuaTeX I used the code from this post (which is also implemented in pdftexcmds
). However I used a slightly modified version that does not use a protecteddef
to allow the returned pdfelapsedtime
to be f
-expanded by l3fp
.
I don't know if this is possible in XeTeX without resorting to system commands...
add a comment |Â
up vote
3
down vote
With pdfTeX you can simulate the behaviour using pdfresettimer
and pdfelapsedtime
. I used some expl3
wrappers to make the same syntax as the ConTeXt version.
documentclassarticle
usepackagexparse
usepackagetikz
%% For LuaTeX
% defpdfresettimerdirectluapdfelapsedtimer_basetime = os.clock()
% defpdfelapsedtimedirectluatex.print((os.clock()-pdfelapsedtimer_basetime)*65536)
%%
ExplSyntaxOn
cs_set_eq:NN __tfo_start_timer: pdfresettimer
cs_set_eq:NN __tfo_elapsed_time: pdfelapsedtime
cs_new:Npn __tfo_output:n #1
iow_term:x
>~#1~feature~tests~done~
(fp_eval:n round ( __tfo_elapsed_time: / 65536 , 3 ) s)
cs_new:Npn __tfo_run_n_times:nn #1 #2
if_int_compare:w #1 > 0 scan_stop:
exp_after:wN __tfo_run_n_times:nn
exp_after:wN int_value:w __int_eval:w #1 - 1 #2
fi:
NewDocumentCommandTestFeatureOnce
m m
__tfo_start_timer:
__tfo_run_n_times:nn #1 #2
__tfo_output:n #1
ExplSyntaxOff
begindocument
TestFeatureOnce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
enddocument
For LuaTeX I used the code from this post (which is also implemented in pdftexcmds
). However I used a slightly modified version that does not use a protecteddef
to allow the returned pdfelapsedtime
to be f
-expanded by l3fp
.
I don't know if this is possible in XeTeX without resorting to system commands...
add a comment |Â
up vote
3
down vote
up vote
3
down vote
With pdfTeX you can simulate the behaviour using pdfresettimer
and pdfelapsedtime
. I used some expl3
wrappers to make the same syntax as the ConTeXt version.
documentclassarticle
usepackagexparse
usepackagetikz
%% For LuaTeX
% defpdfresettimerdirectluapdfelapsedtimer_basetime = os.clock()
% defpdfelapsedtimedirectluatex.print((os.clock()-pdfelapsedtimer_basetime)*65536)
%%
ExplSyntaxOn
cs_set_eq:NN __tfo_start_timer: pdfresettimer
cs_set_eq:NN __tfo_elapsed_time: pdfelapsedtime
cs_new:Npn __tfo_output:n #1
iow_term:x
>~#1~feature~tests~done~
(fp_eval:n round ( __tfo_elapsed_time: / 65536 , 3 ) s)
cs_new:Npn __tfo_run_n_times:nn #1 #2
if_int_compare:w #1 > 0 scan_stop:
exp_after:wN __tfo_run_n_times:nn
exp_after:wN int_value:w __int_eval:w #1 - 1 #2
fi:
NewDocumentCommandTestFeatureOnce
m m
__tfo_start_timer:
__tfo_run_n_times:nn #1 #2
__tfo_output:n #1
ExplSyntaxOff
begindocument
TestFeatureOnce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
enddocument
For LuaTeX I used the code from this post (which is also implemented in pdftexcmds
). However I used a slightly modified version that does not use a protecteddef
to allow the returned pdfelapsedtime
to be f
-expanded by l3fp
.
I don't know if this is possible in XeTeX without resorting to system commands...
With pdfTeX you can simulate the behaviour using pdfresettimer
and pdfelapsedtime
. I used some expl3
wrappers to make the same syntax as the ConTeXt version.
documentclassarticle
usepackagexparse
usepackagetikz
%% For LuaTeX
% defpdfresettimerdirectluapdfelapsedtimer_basetime = os.clock()
% defpdfelapsedtimedirectluatex.print((os.clock()-pdfelapsedtimer_basetime)*65536)
%%
ExplSyntaxOn
cs_set_eq:NN __tfo_start_timer: pdfresettimer
cs_set_eq:NN __tfo_elapsed_time: pdfelapsedtime
cs_new:Npn __tfo_output:n #1
iow_term:x
>~#1~feature~tests~done~
(fp_eval:n round ( __tfo_elapsed_time: / 65536 , 3 ) s)
cs_new:Npn __tfo_run_n_times:nn #1 #2
if_int_compare:w #1 > 0 scan_stop:
exp_after:wN __tfo_run_n_times:nn
exp_after:wN int_value:w __int_eval:w #1 - 1 #2
fi:
NewDocumentCommandTestFeatureOnce
m m
__tfo_start_timer:
__tfo_run_n_times:nn #1 #2
__tfo_output:n #1
ExplSyntaxOff
begindocument
TestFeatureOnce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
enddocument
For LuaTeX I used the code from this post (which is also implemented in pdftexcmds
). However I used a slightly modified version that does not use a protecteddef
to allow the returned pdfelapsedtime
to be f
-expanded by l3fp
.
I don't know if this is possible in XeTeX without resorting to system commands...
edited 16 mins ago
answered 1 hour ago
Phelype Oleinik
18.9k54173
18.9k54173
add a comment |Â
add a comment |Â
up vote
2
down vote
For all I know, there's no such macro in the LaTeX2e base (perhaps LaTeX3 has something equivalent?). But we can look up the definition of testfeatureonce
in the ConTeXt source code. The relevant definitions are in the syst-aux
module.
That implementation makes use of the eTeX primitives pdfresettimer
and pdfelapsedtime
to reset an internal timer and get the elapsed time since the last reset, respectively. I didn't find a proper source for this, but it seems 65536 equals one second in the value returned by pdfelapsedtime
.
A reimplementation in pure LaTeX code might look like this:
documentclassarticle
usepackagetikz
makeatletter
letresettimer=pdfresettimer
letelapsedtime=pdfelapsedtime
newcountc@syst@helpers@test@feature@n
newcountc@syst@helpers@test@feature@m
newcommandtestfeature[2]%
c@syst@helpers@test@feature@m=#1relax
defsyst@helpers@test@feature@step%
advancec@syst@helpers@test@feature@n by 1relax
ifnumc@syst@helpers@test@feature@n>c@syst@helpers@test@feature@melse
#2expandaftersyst@helpers@test@feature@step
fi
%
retestfeature
newcommandretestfeature
bgroup
ifcaseinteractionmode letwaitrelax fi
resettimer
c@syst@helpers@test@feature@n=0relax
syst@helpers@test@feature@step
wait
egroup
newcommandtestfeatureonce[2]%
begingroup
letwaitrelax
testfeature#1#2%
endgroup
makeatother
begindocument
testfeatureonce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
theelapsedtime
enddocument
Thanks! I had looked at that definition but didn't realize that etex provides the primitivespdfresettimer
andpdfelapsedtime
.
â Aditya
45 mins ago
To make this solution work inluatex
, we need to follow the approach used in this answer
â Aditya
30 mins ago
add a comment |Â
up vote
2
down vote
For all I know, there's no such macro in the LaTeX2e base (perhaps LaTeX3 has something equivalent?). But we can look up the definition of testfeatureonce
in the ConTeXt source code. The relevant definitions are in the syst-aux
module.
That implementation makes use of the eTeX primitives pdfresettimer
and pdfelapsedtime
to reset an internal timer and get the elapsed time since the last reset, respectively. I didn't find a proper source for this, but it seems 65536 equals one second in the value returned by pdfelapsedtime
.
A reimplementation in pure LaTeX code might look like this:
documentclassarticle
usepackagetikz
makeatletter
letresettimer=pdfresettimer
letelapsedtime=pdfelapsedtime
newcountc@syst@helpers@test@feature@n
newcountc@syst@helpers@test@feature@m
newcommandtestfeature[2]%
c@syst@helpers@test@feature@m=#1relax
defsyst@helpers@test@feature@step%
advancec@syst@helpers@test@feature@n by 1relax
ifnumc@syst@helpers@test@feature@n>c@syst@helpers@test@feature@melse
#2expandaftersyst@helpers@test@feature@step
fi
%
retestfeature
newcommandretestfeature
bgroup
ifcaseinteractionmode letwaitrelax fi
resettimer
c@syst@helpers@test@feature@n=0relax
syst@helpers@test@feature@step
wait
egroup
newcommandtestfeatureonce[2]%
begingroup
letwaitrelax
testfeature#1#2%
endgroup
makeatother
begindocument
testfeatureonce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
theelapsedtime
enddocument
Thanks! I had looked at that definition but didn't realize that etex provides the primitivespdfresettimer
andpdfelapsedtime
.
â Aditya
45 mins ago
To make this solution work inluatex
, we need to follow the approach used in this answer
â Aditya
30 mins ago
add a comment |Â
up vote
2
down vote
up vote
2
down vote
For all I know, there's no such macro in the LaTeX2e base (perhaps LaTeX3 has something equivalent?). But we can look up the definition of testfeatureonce
in the ConTeXt source code. The relevant definitions are in the syst-aux
module.
That implementation makes use of the eTeX primitives pdfresettimer
and pdfelapsedtime
to reset an internal timer and get the elapsed time since the last reset, respectively. I didn't find a proper source for this, but it seems 65536 equals one second in the value returned by pdfelapsedtime
.
A reimplementation in pure LaTeX code might look like this:
documentclassarticle
usepackagetikz
makeatletter
letresettimer=pdfresettimer
letelapsedtime=pdfelapsedtime
newcountc@syst@helpers@test@feature@n
newcountc@syst@helpers@test@feature@m
newcommandtestfeature[2]%
c@syst@helpers@test@feature@m=#1relax
defsyst@helpers@test@feature@step%
advancec@syst@helpers@test@feature@n by 1relax
ifnumc@syst@helpers@test@feature@n>c@syst@helpers@test@feature@melse
#2expandaftersyst@helpers@test@feature@step
fi
%
retestfeature
newcommandretestfeature
bgroup
ifcaseinteractionmode letwaitrelax fi
resettimer
c@syst@helpers@test@feature@n=0relax
syst@helpers@test@feature@step
wait
egroup
newcommandtestfeatureonce[2]%
begingroup
letwaitrelax
testfeature#1#2%
endgroup
makeatother
begindocument
testfeatureonce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
theelapsedtime
enddocument
For all I know, there's no such macro in the LaTeX2e base (perhaps LaTeX3 has something equivalent?). But we can look up the definition of testfeatureonce
in the ConTeXt source code. The relevant definitions are in the syst-aux
module.
That implementation makes use of the eTeX primitives pdfresettimer
and pdfelapsedtime
to reset an internal timer and get the elapsed time since the last reset, respectively. I didn't find a proper source for this, but it seems 65536 equals one second in the value returned by pdfelapsedtime
.
A reimplementation in pure LaTeX code might look like this:
documentclassarticle
usepackagetikz
makeatletter
letresettimer=pdfresettimer
letelapsedtime=pdfelapsedtime
newcountc@syst@helpers@test@feature@n
newcountc@syst@helpers@test@feature@m
newcommandtestfeature[2]%
c@syst@helpers@test@feature@m=#1relax
defsyst@helpers@test@feature@step%
advancec@syst@helpers@test@feature@n by 1relax
ifnumc@syst@helpers@test@feature@n>c@syst@helpers@test@feature@melse
#2expandaftersyst@helpers@test@feature@step
fi
%
retestfeature
newcommandretestfeature
bgroup
ifcaseinteractionmode letwaitrelax fi
resettimer
c@syst@helpers@test@feature@n=0relax
syst@helpers@test@feature@step
wait
egroup
newcommandtestfeatureonce[2]%
begingroup
letwaitrelax
testfeature#1#2%
endgroup
makeatother
begindocument
testfeatureonce1000
setbox0hbox
tikz draw (0,0) -- (1cm, 1cm);
theelapsedtime
enddocument
answered 1 hour ago
siracusa
4,10911027
4,10911027
Thanks! I had looked at that definition but didn't realize that etex provides the primitivespdfresettimer
andpdfelapsedtime
.
â Aditya
45 mins ago
To make this solution work inluatex
, we need to follow the approach used in this answer
â Aditya
30 mins ago
add a comment |Â
Thanks! I had looked at that definition but didn't realize that etex provides the primitivespdfresettimer
andpdfelapsedtime
.
â Aditya
45 mins ago
To make this solution work inluatex
, we need to follow the approach used in this answer
â Aditya
30 mins ago
Thanks! I had looked at that definition but didn't realize that etex provides the primitives
pdfresettimer
and pdfelapsedtime
.â Aditya
45 mins ago
Thanks! I had looked at that definition but didn't realize that etex provides the primitives
pdfresettimer
and pdfelapsedtime
.â Aditya
45 mins ago
To make this solution work in
luatex
, we need to follow the approach used in this answerâ Aditya
30 mins ago
To make this solution work in
luatex
, we need to follow the approach used in this answerâ Aditya
30 mins ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f456316%2fwhat-is-the-latex-equivalent-of-context-testfeatureonce-to-benchmark-performanc%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password