Last active
May 26, 2019 10:09
-
-
Save zauguin/520b6dd6e4fb3cbc5776e0aed68f282e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local func_tbl = lua.get_functions_table() | |
local set_lua = token.set_lua | |
local new_luafunction = luatexbase.new_luafunction | |
return function(name, func, ...) | |
local idx = new_luafunction(name) | |
set_lua(name, idx, ...) | |
func_tbl[idx] = func | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Current implementation | |
8.44e-6 seconds (33 ops) | |
1.12e-5 seconds (43.8 ops) | |
% Current implementation (again) | |
8.92e-6 seconds (34.3 ops) | |
1.1e-5 seconds (42.8 ops) | |
% token.scan_string | |
6.82e-6 seconds (26.6 ops) | |
7.57e-6 seconds (29.3 ops) | |
% token.scan_string + luadef | |
1.82e-6 seconds (7.12 ops) | |
2.45e-6 seconds (9.55 ops) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\documentclass{article} | |
\usepackage{expl3,l3benchmark} | |
\begin{document} | |
\ExplSyntaxOn | |
\benchmark:n{ | |
\str_if_eq:eeTF{Some simple string}{Some simple string}{}{} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{\string\relax\csstring\ and enjoy your life}{\noexpand\relax and enjoy your life}{}{} | |
} | |
\cs_if_exist:NT \tex_luatexversion:D | |
{ | |
\cs_set:Npn \__str_if_eq:nn #1#2 | |
{ | |
\lua_now:e | |
{ | |
l3kernel.strcmp | |
( | |
" \__str_escape:n {#1} " , | |
" \__str_escape:n {#2} " | |
) | |
} | |
} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{Some simple string}{Some simple string}{}{} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{\string\relax\csstring\ and enjoy your life}{\noexpand\relax and enjoy your life}{}{} | |
} | |
\cs_if_exist:NT \tex_luatexversion:D | |
{ | |
\cs_set:Npn \__str_if_eq:nn | |
{ | |
\lua_now:e | |
{ | |
l3kernel.strcmp | |
( | |
token.scan_string(), | |
token.scan_string() | |
) | |
} | |
} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{Some simple string}{Some simple string}{}{} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{\string\relax\csstring\ and enjoy your life}{\noexpand\relax and enjoy your life}{}{} | |
} | |
\cs_if_exist:NT \tex_luatexversion:D | |
{ | |
\lua_now:e | |
{ | |
require'luacmd'('__str_if_eq:nn', function() | |
l3kernel.strcmp | |
( | |
token.scan_string(), | |
token.scan_string() | |
) | |
end) | |
} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{Some simple string}{Some simple string}{}{} | |
} | |
\benchmark:n{ | |
\str_if_eq:eeTF{\string\relax\csstring\ and enjoy your life}{\noexpand\relax and enjoy your life}{}{} | |
} | |
\ExplSyntaxOff | |
\end{document} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment