| 1 |
\section{Comparisons}\label{sec:cmp} |
| 2 |
|
| 3 |
This section makes some basic comparison between \expkv\ and other \kv\ |
| 4 |
packages. The comparisons are really concise, regarding speed, feature range |
| 5 |
(without listing the features of each package, comparisons are done against the |
| 6 |
base \expkv\ not counting other packages in \expkvbundle\ that extend it, so |
| 7 |
\enquote{bigger feature set} might not necessarily be true if everything is |
| 8 |
included), and bugs and misfeatures. |
| 9 |
|
| 10 |
Comparisons of speed are done with a very simple test key and the help of the |
| 11 |
\pkg{l3benchmark} package. The key and its usage should be equivalent to |
| 12 |
\begin{enverb}[no-tcb] |
| 13 |
\protected\ekvdef{test}{height}{\def\myheight{#1}} |
| 14 |
\ekvsetdef\expkvtest{test} |
| 15 |
\expkvtest{ height = 6 } |
| 16 |
\end{enverb} |
| 17 |
and only the usage of the key, not its definition, is benchmarked. For the |
| 18 |
impatient, the essence of these comparisons regarding speed and buggy |
| 19 |
behaviour is contained in \autoref{tab:comp}. |
| 20 |
|
| 21 |
As far as I know \expkv\ is the only fully expandable \kv\ parser. I tried to |
| 22 |
compare \expkv\ to every \kv\ package listed on |
| 23 |
\href{https://ctan.org/topic/keyval}{CTAN}, however, one might notice that |
| 24 |
some of those are missing from this list. That's because I didn't get the |
| 25 |
others to work due to bugs, or because they just provide wrappers around other |
| 26 |
packages in this list. |
| 27 |
|
| 28 |
In this subsection is no benchmark of |\ekvparse| and |\keyval_parse:NNn| |
| 29 |
contained, as most other packages don't provide equivalent features to my |
| 30 |
knowledge. |\ekvparse| is slightly faster than |\ekvset|, but keep in mind |
| 31 |
that it does less. The same is true for |\keyval_parse:NNn| compared to |
| 32 |
|\keys_set:nn| of \pkg{expl3} (where the difference is much bigger). Comparing |
| 33 |
just the two, |\ekvparse| is a tad faster than |\keyval_parse:NNn| because of |
| 34 |
two tests (for empty key names and only a single equal sign) which are |
| 35 |
omitted. |
| 36 |
|
| 37 |
\paragraph{\pkg{keyval}} is the fastest \kv\ package there is and has a minimal |
| 38 |
feature set with a slightly different way how it handles keys without values |
| 39 |
compared to \expkv. That might be considered a drawback, as it limits the |
| 40 |
versatility, but also as an advantage, as it might reduce doubled code. Keep in |
| 41 |
mind that as soon as someone loads \pkg{xkeyval} the performance of \pkg{keyval} |
| 42 |
gets replaced by \pkg{xkeyval}'s. |
| 43 |
|
| 44 |
Also \pkg{keyval} has a \pmso{bug}feature, which unfortunately can't really be |
| 45 |
resolved without breaking backwards compatibility for \emph{many} documents, |
| 46 |
namely it strips braces from the argument before stripping spaces if the |
| 47 |
outer most braces aren't surrounded by spaces, also it might strip more than one |
| 48 |
set of braces. Hence all of the following are equivalent in their outcome, |
| 49 |
though the last two lines should result in something different than the first |
| 50 |
two: |
| 51 |
\begin{enverb}[no-tcb] |
| 52 |
\setkeys{foo}{bar=baz} |
| 53 |
\setkeys{foo}{bar= {baz}} |
| 54 |
\setkeys{foo}{bar={ baz}} % should be ` baz' |
| 55 |
\setkeys{foo}{bar={{baz}}} % should be `{baz}' |
| 56 |
\end{enverb} |
| 57 |
|
| 58 |
\pkg{keyval} doesn't work with non-standard category codes of |=| and |,|. Also |
| 59 |
if a \kv\ pair contains multiple equals signs outside of braces everything post |
| 60 |
the first is silently ignored so the following two inputs yield identical |
| 61 |
outputs: |
| 62 |
\begin{enverb}[no-tcb,lst=belowskip=0pt] |
| 63 |
\setkeys{foo}{bar=baz} |
| 64 |
\setkeys{foo}{bar=baz=and more} |
| 65 |
\end{enverb} |
| 66 |
|
| 67 |
\paragraph{\pkg{xkeyval}} is pretty slow (yet not the slowest), but it provides |
| 68 |
more functionality, e.g., it has an interface to disable a list of keys, can |
| 69 |
search multiple sets simultaneously, and has an intriguing mechanism it calls |
| 70 |
\enquote{Pointers} to save the value of particular keys for later reuse. It |
| 71 |
contains the same bug as \pkg{keyval} as it has to be compatible with it by |
| 72 |
design (it replaces \pkg{keyval}'s frontend), but also adds even more cases in |
| 73 |
which braces are stripped that shouldn't be stripped, worsening the situation. |
| 74 |
|
| 75 |
\pkg{xkeyval} does work with non-standard category codes of |=| and |,|, but the |
| 76 |
used mechanism fails if the input contains a mix of different category codes for |
| 77 |
the same character. Just like with \pkg{keyval} equals signs after the first and |
| 78 |
everything after those is ignored. |
| 79 |
|
| 80 |
\paragraph{\pkg{ltxkeys}} is no longer compatible with the \LaTeX\ kernel |
| 81 |
starting with the release 2020-10-01. It is by far the slowest \kv\ package I've |
| 82 |
tested -- which is funny, because it aims to be ``[\ldots] faster [\ldots] than |
| 83 |
these earlier packages [referring to \pkg{keyval} and \pkg{xkeyval}].'' It needs |
| 84 |
more time to parse zero~keys than five of the packages in this comparison need |
| 85 |
to parse 100~keys. Since it aims to have a bigger feature set than |
| 86 |
\pkg{xkeyval}, it most definitely also has a bigger feature set than \expkv. |
| 87 |
Also, it can't parse |\long| input, so as soon as your values contain a |\par|, |
| 88 |
it'll throw errors. Furthermore, \pkg{ltxkeys} doesn't strip outer braces at |
| 89 |
all by design, which, imho, is a weird design choice. Some of the more |
| 90 |
intriguing features (e.g., the |\argpattern| mechanism) didn't work for me. In |
| 91 |
addition \pkg{ltxkeys} loads \pkg{catoptions} which is known to introduce bugs |
| 92 |
(e.g., see \url{https://tex.stackexchange.com/questions/461783}). Because it is |
| 93 |
no longer compatible with the kernel, I stop benchmarking it (so the numbers |
| 94 |
listed here and in \autoref{tab:comp} regarding \pkg{ltxkeys} were last updated |
| 95 |
on 2020-10-05). |
| 96 |
|
| 97 |
\pkg{ltxkeys} works with non-standard category codes, it also silently ignores |
| 98 |
any additional equals signs and the following tokens. |
| 99 |
|
| 100 |
\paragraph{\pkg{l3keys}} is at the slower end of the midfield yet not unusably |
| 101 |
slow, but has an, imho, great interface to define keys. It strips \emph{all} |
| 102 |
outer spaces, even if somehow multiple spaces ended up on either end. It offers |
| 103 |
more features, but has pretty much been bound to \pkg{expl3} code before. |
| 104 |
Nowadays the \LaTeX\ kernel has an interface with the macros |\DeclareKeys|, |
| 105 |
|\SetKeys|, and |\ProcessKeyOptions| that provides access to \pkg{l3keys} from |
| 106 |
the \LaTeXe\ layer as well as parsing package options with it. Because of the |
| 107 |
|\ProcessKeyOptions| macro and its features the only two viable options to |
| 108 |
provide \kv\ options for new projects in my opinion are the kernel's methods and |
| 109 |
\expkvo\ as those are the only two until now up to my knowledge that support |
| 110 |
parsing the raw options, and future options. |
| 111 |
|
| 112 |
\pkg{l3keys} handles active commas and equals signs fine. Multiple equals signs |
| 113 |
lead to an error if additional equals signs aren't nested inside of braces, so |
| 114 |
perfectly predictable behaviour here. |
| 115 |
|
| 116 |
\paragraph{\pkg{pgfkeys}} is among the top~4 of speed if one uses |\pgfqkeys| |
| 117 |
over |\pgfkeys|, else the initialisation parsing the family path takes roughly |
| 118 |
\SI{43}{\ops} and moves it two spots down the list (so in \autoref{tab:comp} |
| 119 |
both $p_0$ and $T_0$ would be about \SI{43}{\ops} bigger if |
| 120 |
|\pgfkeys{|\meta{path}|/.cd,|\meta{keys}|}| was used instead). It has an |
| 121 |
\emph{enormous} feature set. It stores keys in a way that reminds one of folders |
| 122 |
in a Unix system which allows interesting features and has other syntactic |
| 123 |
sugars. It is another package that implements something like the \expnotation\ |
| 124 |
with less different options though. To get the best performance |\pgfqkeys| was |
| 125 |
used in the benchmark. It has the same or a very similar bug \pkg{keyval} has. |
| 126 |
The brace bug (and also the category fragility) can be fixed by \pkg{pgfkeyx}, |
| 127 |
but this package was last updated in 2012 and it slows down |\pgfkeys| by |
| 128 |
factor~\num{8}. Also \pkg{pgfkeyx} is no longer compatible with versions of |
| 129 |
\pkg{pgfkeys} newer than 2020-05-25. |
| 130 |
|
| 131 |
\pkg{pgfkeys} silently drops anything after the second unbraced equals sign in a |
| 132 |
\kv\ pair. |
| 133 |
|
| 134 |
\paragraph{\pkg{kvsetkeys} with \pkg{kvdefinekeys}} is in the slower midfield, |
| 135 |
but it works even if commas and equals have category codes different from 12 |
| 136 |
(just as some other packages in this list). It has quadratic run-time unlike |
| 137 |
most other \kv\ implementations which behave linear. The features of the |
| 138 |
keys are equal to those of \pkg{keyval}, the parser adds handling of unknown |
| 139 |
keys. |
| 140 |
|
| 141 |
\pkg{kvsetkeys} does include any additional equals sign in the value. But any |
| 142 |
active equals sign is turned into one of category code 12 if it's not nested in |
| 143 |
braces. Also spaces around superfluous equals signs are stripped. So the |
| 144 |
following all result in the same: |
| 145 |
\begin{enverb}[no-tcb,lst=belowskip=0pt] |
| 146 |
\kvsetkeys{foo}{bar=baz=morebaz} |
| 147 |
\kvsetkeys{foo}{bar=baz =morebaz} |
| 148 |
\kvsetkeys{foo}{bar=baz= morebaz} |
| 149 |
\kvsetkeys{foo}{bar=baz = morebaz} |
| 150 |
\end{enverb} |
| 151 |
|
| 152 |
\paragraph{\pkg{options}} is in the midfield of speed. It is faster per |
| 153 |
individual key than \pkg{pgfkeys} but has no shortcut like |\pgfqkeys|. |
| 154 |
It has a much bigger feature set than \expkv. Similar to \pkg{pgfkeys} it uses a |
| 155 |
folder like structure, makes searching multiple paths easy, incorporates package |
| 156 |
options and more. It also features a form of expansion control, predefined |
| 157 |
expansion kinds are limited though one can define additional ones. Unfortunately |
| 158 |
it also suffers from the premature unbracing bug \pkg{keyval} has. |
| 159 |
|
| 160 |
\pkg{options} can't handle non-standard category codes and will silently ignore |
| 161 |
superfluous equals signs and following tokens. |
| 162 |
|
| 163 |
\paragraph{\pkg{simplekv}} is hard to compare because I don't speak French (so |
| 164 |
I don't understand the documentation). There was an update released on |
| 165 |
2020-04-27 which greatly improved the package's performance and added |
| 166 |
functionality so that it can be used more like most of the other \kv\ |
| 167 |
packages. Speed wise it is pretty close to \expkv. Regarding unknown keys it got |
| 168 |
a very interesting behaviour. It doesn't throw an error, but stores the \val\ in |
| 169 |
a new entry accessible with \cs[no-index]{useKV}. Also if you omit \val\ it |
| 170 |
stores |true| for that \key. |
| 171 |
|
| 172 |
\pkg{simplekv} can't correctly handle non-standard category codes. It silently |
| 173 |
ignores any unbraced equals sign beyond the first and any following tokens. |
| 174 |
|
| 175 |
\paragraph{\protect\yax} is the second slowest package I've tested. It has a |
| 176 |
pretty strange syntax for the \TeX-world, imho, and again a direct equivalent is |
| 177 |
hard to define (don't understand me wrong, I don't say I don't like the syntax, |
| 178 |
quite the contrary, it's just atypical). It has the premature unbracing bug, |
| 179 |
too. \yax\ features some prefixes one can use to make an assignment use |\edef|, |
| 180 |
|\gdef| or |\xdef| so has something that comes close to expansion control. Also |
| 181 |
somehow loading \yax\ broke \pkg{options} for me. The tested definition was: |
| 182 |
\begin{enverb}[no-tcb] |
| 183 |
\usepackage{yax} |
| 184 |
\defactiveparameter yax {\storevalue\myheight yax:height } % setup |
| 185 |
\setparameterlist{yax}{ height = 6 } % benchmark |
| 186 |
\end{enverb} |
| 187 |
This seems important to state as \yax\ supports two different input syntaxes, |
| 188 |
the tested one was the one closer to traditional \kv\ input. |
| 189 |
|
| 190 |
\yax\ won't handle non-standard category codes correctly. Superfluous equals |
| 191 |
signs end up in the value in an unaltered form (just like with \expkv). |
| 192 |
|
| 193 |
\begin{table} |
| 194 |
\def\fnsym{\textcolor{red!80!black}{*}}% |
| 195 |
\sisetup{round-precision=1, round-mode=places}% |
| 196 |
\begingroup |
| 197 |
\centering |
| 198 |
\newcommand*\yes{\textcolor{red!80!black} {yes}}^^A |
| 199 |
\newcommand*\no {\textcolor{green!80!black}{no}}^^A |
| 200 |
\caption[Comparison of \kv\ packages] |
| 201 |
{^^A |
| 202 |
Comparison of \kv\ packages. The packages are ordered from |
| 203 |
fastest to slowest for one \kv\ pair. Benchmarking was done using |
| 204 |
\pkg{l3benchmark} and the scripts in the \file{Benchmarks} folder |
| 205 |
of \href{https://github.com/Skillmon/tex_expkv}{the original \expkv's git |
| 206 |
repository}. |
| 207 |
The columns $p_i$ are the polynomial coefficients of a linear fit to the |
| 208 |
run-time, $p_0$ can be interpreted as the overhead for initialisation |
| 209 |
and $p_1$ the cost per key. The $T_0$ column is the actual mean ops |
| 210 |
needed for an empty list argument, as the linear fit doesn't match that |
| 211 |
point well in general. The column ``BB'' lists whether the |
| 212 |
parsing is affected by some sort of brace bug, ``CF'' stands for |
| 213 |
category code fragile and lists whether the parsing breaks with active |
| 214 |
commas or equal signs.^^A |
| 215 |
\label{tab:comp}^^A |
| 216 |
} |
| 217 |
\begin{tabular} |
| 218 |
{>{\collectcell\pkg}l<{\endcollectcell}*3{S[table-format=4.1]}ccc} |
| 219 |
\toprule |
| 220 |
\rmfamily Package & {$p_1$} & {$p_0$} & {$T_0$}& BB & CF & Date \\ |
| 221 |
\midrule |
| 222 |
keyval & 13.557 & 2.202 & 7.185 & \yes & \yes & 2022-05-29 \\ |
| 223 |
\expkv & 16.669 & 3.132 & 5.836 & \no & \no & 2023-01-10 \\ |
| 224 |
simplekv & 19.943 & 2.850 & 15.120 & \no & \yes & 2022-10-01 \\ |
| 225 |
pgfkeys & 24.465 & 2.244 & 10.283 & \yes & \yes & 2021-05-15 \\ |
| 226 |
options & 23.255 & 16.160 & 20.400 & \yes & \yes & 2015-03-01 \\ |
| 227 |
kvsetkeys & {\fnsym} & {\fnsym} & 40.360 & \no & \no & 2022-10-05 \\ |
| 228 |
l3keys & 70.643 & 35.602 & 32.230 & \no & \no & 2022-12-17 \\ |
| 229 |
xkeyval & 255.906 & 221.276 & 173.400 & \yes & \yes & 2022-06-16 \\ |
| 230 |
\yax & 438.242 & 131.846 & 114.800 & \yes & \yes & 2010-01-22 \\ |
| 231 |
ltxkeys & 3400.142 & 4737.958 & 5368.000 & \no & \no & 2012-11-17 \\ |
| 232 |
\bottomrule |
| 233 |
\end{tabular} |
| 234 |
\par |
| 235 |
\endgroup |
| 236 |
\medskip |
| 237 |
\fnsym For \pkg{kvsetkeys} the linear model used for the other |
| 238 |
packages is a poor fit, \pkg{kvsetkeys} seems to have approximately |
| 239 |
quadratic run-time, the coefficients of the second degree polynomial fit are |
| 240 |
$p_2=\num{7.617}$, $p_1=\num{47.727}$, and $p_0=\num{57.988}$. Of course the |
| 241 |
other packages might not really have linear run-time, but at least from 1~to |
| 242 |
20~keys the fits don't seem too bad. If one extrapolates the fits for 100 |
| 243 |
\kv\ pairs one finds that most of them match pretty well, the exception |
| 244 |
being \pkg{ltxkeys}, which behaves quadratic as well with |
| 245 |
$p_2=\num{23.500}$, $p_1=\num{2906.634}$, and $p_0=\num{6547.489}$. |
| 246 |
\end{table} |