You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are a few options in Emacs Lisp for looking up values in associative data structures: association lists (alists), property lists (plists), and hash tables. Which one performs best in a situation may depend on several factors. This benchmark shows what may be a common case: looking up values using a string as the key. We compare several combinations, including the case of prepending a prefix to the string, interning it, and looking up the resulting symbol (which might be done, e.g. when looking up a function to call based on the value of a string).
541
+
542
+
#+BEGIN_SRC elisp :exports both :cache yes
543
+
(bench-multi-lets :times 10000 :ensure-equal t
544
+
:lets (("with 26 keys"
545
+
((char-range (cons ?A ?Z))
546
+
(strings (cl-loop for char from (car char-range) to (cdr char-range)
We see that hash-tables are generally the fastest solution.
609
+
610
+
When using an alist with 26 keys, it's faster to concat and intern a string and then look up the resulting symbol in the alist with ~eq~ as the test function (the =symbols/concat/intern/alist-get= test) than to lookup the string directly with ~equal~ (the =strings/alist-get/equal= test).
611
+
612
+
Also, perhaps surprisingly, when looking up a string in an alist, using ~equal~ as the test function may be faster than using the type-specific ~string=~ function (possibly indicating an optimization to be made in Emacs's C code).
613
+
614
+
***** TODO Compare looking up interned symbols in obarray instead of hash table
0 commit comments