token register vs. macro register
Clash Royale CLAN TAG#URR8PPP
up vote
6
down vote
favorite
Consider the following simple code:
def@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
The same result can be achieved with:
toksdeftokszero0
toksdeftokstwo2
def@@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
Is there any significant difference? (Aside from toksdef
.) Which one is preferable?
(I can think of one difference. If either UNDEF or DEF contains #
, then the macro register version would fail.)
tex-core
add a comment |Â
up vote
6
down vote
favorite
Consider the following simple code:
def@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
The same result can be achieved with:
toksdeftokszero0
toksdeftokstwo2
def@@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
Is there any significant difference? (Aside from toksdef
.) Which one is preferable?
(I can think of one difference. If either UNDEF or DEF contains #
, then the macro register version would fail.)
tex-core
In eTeX you can imitate toks registers withprotectededefreservedunexpanded#1
if I remember correctly.toks
is â€Âfasterâ€Â, but probably the difference in your use doesn't really matter. In LaTeX3 the macro version is used for almost everything the user does.
– Manuel
1 hour ago
1
You've marked this as tex-core but the use ofreserved@a
suggests LaTeX ...
– Joseph Wright♦
1 hour ago
add a comment |Â
up vote
6
down vote
favorite
up vote
6
down vote
favorite
Consider the following simple code:
def@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
The same result can be achieved with:
toksdeftokszero0
toksdeftokstwo2
def@@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
Is there any significant difference? (Aside from toksdef
.) Which one is preferable?
(I can think of one difference. If either UNDEF or DEF contains #
, then the macro register version would fail.)
tex-core
Consider the following simple code:
def@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
The same result can be achieved with:
toksdeftokszero0
toksdeftokstwo2
def@@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
Is there any significant difference? (Aside from toksdef
.) Which one is preferable?
(I can think of one difference. If either UNDEF or DEF contains #
, then the macro register version would fail.)
tex-core
tex-core
edited 1 hour ago
Joseph Wright♦
198k21545866
198k21545866
asked 3 hours ago
user5938
1636
1636
In eTeX you can imitate toks registers withprotectededefreservedunexpanded#1
if I remember correctly.toks
is â€Âfasterâ€Â, but probably the difference in your use doesn't really matter. In LaTeX3 the macro version is used for almost everything the user does.
– Manuel
1 hour ago
1
You've marked this as tex-core but the use ofreserved@a
suggests LaTeX ...
– Joseph Wright♦
1 hour ago
add a comment |Â
In eTeX you can imitate toks registers withprotectededefreservedunexpanded#1
if I remember correctly.toks
is â€Âfasterâ€Â, but probably the difference in your use doesn't really matter. In LaTeX3 the macro version is used for almost everything the user does.
– Manuel
1 hour ago
1
You've marked this as tex-core but the use ofreserved@a
suggests LaTeX ...
– Joseph Wright♦
1 hour ago
In eTeX you can imitate toks registers with
protectededefreservedunexpanded#1
if I remember correctly. toks
is â€Âfasterâ€Â, but probably the difference in your use doesn't really matter. In LaTeX3 the macro version is used for almost everything the user does.– Manuel
1 hour ago
In eTeX you can imitate toks registers with
protectededefreservedunexpanded#1
if I remember correctly. toks
is â€Âfasterâ€Â, but probably the difference in your use doesn't really matter. In LaTeX3 the macro version is used for almost everything the user does.– Manuel
1 hour ago
1
1
You've marked this as tex-core but the use of
reserved@a
suggests LaTeX ...– Joseph Wright♦
1 hour ago
You've marked this as tex-core but the use of
reserved@a
suggests LaTeX ...– Joseph Wright♦
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
Not a very complete benchmark, but it should give the idea. Consider the following testundef.tex
file
catcode`@=11
defa@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1%
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
toksdeftokszero0
toksdeftokstwo2
defb@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1%
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
def@firstoftwo#1#2#1
def@secondoftwo#1#2#2
defc@ifundefined#1% csUNDEFDEF
ifdefined#1%
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
expandafterletexpandafterifundefinedcsnametest @ifundefinedendcsname
count255=0
loopifnumcount255<1000000
ifundefinedfoorelaxrelax
ifundefinedrelaxrelaxrelax
advancecount255 1
repeat
bye
I give three possible definitions of @ifundefined
and then test them by a command line switch. Here's the session transcript
> time pdftex "deftestainput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.871s
user 0m1.844s
sys 0m0.018s
> time pdftex "deftestbinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m2.308s
user 0m2.277s
sys 0m0.021s
> time pdftex "deftestcinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.518s
user 0m1.490s
sys 0m0.017s
It seems that the toks
method is the slowest; the final method, with pure expansion, is faster because there is no storing away and retrieving to do.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
Not a very complete benchmark, but it should give the idea. Consider the following testundef.tex
file
catcode`@=11
defa@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1%
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
toksdeftokszero0
toksdeftokstwo2
defb@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1%
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
def@firstoftwo#1#2#1
def@secondoftwo#1#2#2
defc@ifundefined#1% csUNDEFDEF
ifdefined#1%
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
expandafterletexpandafterifundefinedcsnametest @ifundefinedendcsname
count255=0
loopifnumcount255<1000000
ifundefinedfoorelaxrelax
ifundefinedrelaxrelaxrelax
advancecount255 1
repeat
bye
I give three possible definitions of @ifundefined
and then test them by a command line switch. Here's the session transcript
> time pdftex "deftestainput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.871s
user 0m1.844s
sys 0m0.018s
> time pdftex "deftestbinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m2.308s
user 0m2.277s
sys 0m0.021s
> time pdftex "deftestcinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.518s
user 0m1.490s
sys 0m0.017s
It seems that the toks
method is the slowest; the final method, with pure expansion, is faster because there is no storing away and retrieving to do.
add a comment |Â
up vote
4
down vote
Not a very complete benchmark, but it should give the idea. Consider the following testundef.tex
file
catcode`@=11
defa@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1%
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
toksdeftokszero0
toksdeftokstwo2
defb@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1%
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
def@firstoftwo#1#2#1
def@secondoftwo#1#2#2
defc@ifundefined#1% csUNDEFDEF
ifdefined#1%
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
expandafterletexpandafterifundefinedcsnametest @ifundefinedendcsname
count255=0
loopifnumcount255<1000000
ifundefinedfoorelaxrelax
ifundefinedrelaxrelaxrelax
advancecount255 1
repeat
bye
I give three possible definitions of @ifundefined
and then test them by a command line switch. Here's the session transcript
> time pdftex "deftestainput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.871s
user 0m1.844s
sys 0m0.018s
> time pdftex "deftestbinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m2.308s
user 0m2.277s
sys 0m0.021s
> time pdftex "deftestcinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.518s
user 0m1.490s
sys 0m0.017s
It seems that the toks
method is the slowest; the final method, with pure expansion, is faster because there is no storing away and retrieving to do.
add a comment |Â
up vote
4
down vote
up vote
4
down vote
Not a very complete benchmark, but it should give the idea. Consider the following testundef.tex
file
catcode`@=11
defa@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1%
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
toksdeftokszero0
toksdeftokstwo2
defb@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1%
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
def@firstoftwo#1#2#1
def@secondoftwo#1#2#2
defc@ifundefined#1% csUNDEFDEF
ifdefined#1%
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
expandafterletexpandafterifundefinedcsnametest @ifundefinedendcsname
count255=0
loopifnumcount255<1000000
ifundefinedfoorelaxrelax
ifundefinedrelaxrelaxrelax
advancecount255 1
repeat
bye
I give three possible definitions of @ifundefined
and then test them by a command line switch. Here's the session transcript
> time pdftex "deftestainput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.871s
user 0m1.844s
sys 0m0.018s
> time pdftex "deftestbinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m2.308s
user 0m2.277s
sys 0m0.021s
> time pdftex "deftestcinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.518s
user 0m1.490s
sys 0m0.017s
It seems that the toks
method is the slowest; the final method, with pure expansion, is faster because there is no storing away and retrieving to do.
Not a very complete benchmark, but it should give the idea. Consider the following testundef.tex
file
catcode`@=11
defa@ifundefined#1#2#3% csUNDEFDEF
defreserved@a#2%
defreserved@b#3%
ifdefined#1%
letreserved@creserved@b
else
letreserved@creserved@a
fi
reserved@c
toksdeftokszero0
toksdeftokstwo2
defb@ifundefined#1#2#3% csUNDEFDEF
tokszero#2%
tokstwo#3%
ifdefined#1%
letreserved@ctokstwo
else
letreserved@ctokszero
fi
thereserved@c
def@firstoftwo#1#2#1
def@secondoftwo#1#2#2
defc@ifundefined#1% csUNDEFDEF
ifdefined#1%
expandafter@firstoftwo
else
expandafter@secondoftwo
fi
expandafterletexpandafterifundefinedcsnametest @ifundefinedendcsname
count255=0
loopifnumcount255<1000000
ifundefinedfoorelaxrelax
ifundefinedrelaxrelaxrelax
advancecount255 1
repeat
bye
I give three possible definitions of @ifundefined
and then test them by a command line switch. Here's the session transcript
> time pdftex "deftestainput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.871s
user 0m1.844s
sys 0m0.018s
> time pdftex "deftestbinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m2.308s
user 0m2.277s
sys 0m0.021s
> time pdftex "deftestcinput testundef"
This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018) (preloaded format=pdftex)
restricted write18 enabled.
entering extended mode
(./testundef.tex )
No pages of output.
Transcript written on testundef.log.
real 0m1.518s
user 0m1.490s
sys 0m0.017s
It seems that the toks
method is the slowest; the final method, with pure expansion, is faster because there is no storing away and retrieving to do.
answered 30 mins ago


egreg
689k8518333082
689k8518333082
add a comment |Â
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%2f455208%2ftoken-register-vs-macro-register%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
In eTeX you can imitate toks registers with
protectededefreservedunexpanded#1
if I remember correctly.toks
is â€Âfasterâ€Â, but probably the difference in your use doesn't really matter. In LaTeX3 the macro version is used for almost everything the user does.– Manuel
1 hour ago
1
You've marked this as tex-core but the use of
reserved@a
suggests LaTeX ...– Joseph Wright♦
1 hour ago