Helps a bit, especially the l2s-4 - which is more consistently fast across short/long lists.
_$ (setq test nil)
nil
_$ (length (repeat 10 (setq test (cons "test" test))))
10
_$ (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ",")))
Benchmarking ..... done for 16384 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(L2S-2 TEST ,) 16384 1122 1122 1.06
(L2S-3 TEST ,) 16384 1155 1155 1.03
(L2S-4 TEST ,) 16384 1155 1155 1.03
(L2S TEST ,) 16384 1183 1183 1.00
(STRINGLIST->TOKENSTRING TEST ,) 16384 1184 1184 1.00
--------------------------------------------------------------------------------
_$ (setq test nil)
nil
_$ (length (repeat 10000 (setq test (cons "test" test))))
10000
_$ (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ",")))
Benchmarking ..... done for 128 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(STRINGLIST->TOKENSTRING TEST ,) 128 1949 1949 1.55
(L2S-4 TEST ,) 64 1248 2496 1.21
(L2S-3 TEST ,) 64 1295 2590 1.17
(L2S-2 TEST ,) 64 1372 2744 1.10
(L2S TEST ,) 64 1512 3024 1.00
--------------------------------------------------------------------------------
_$ (setq test nil)
nil
_$ (length (repeat 1000 (setq test (cons "test" test))))
1000
_$ (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ",")))
Benchmarking ..... done for 1024 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(STRINGLIST->TOKENSTRING TEST ,) 1024 1622 1622 1.52
(L2S-4 TEST ,) 1024 1715 1715 1.44
(L2S-3 TEST ,) 512 1031 2062 1.19
(L2S-2 TEST ,) 512 1061 2122 1.16
(L2S TEST ,) 512 1231 2462 1.00
--------------------------------------------------------------------------------
It's only on very long lists where the append apply seems to outperform all. Perhaps I'd go with a conditional function like this:
(defun stringlist
->tokenstring
(source token
/ result
) source)))))
source)))))))
From my tests it uses the fastest version in each case. But it seems the cond screws that up on short lists.
_$ (progn (setq test nil) (repeat 2 (setq test (cons "test" test))) (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ","))))
Benchmarking ..... done for 32768 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(L2S-3 TEST ,) 32768 1856 1856 1.09
(L2S-2 TEST ,) 32768 1857 1857 1.09
(STRINGLIST->TOKENSTRING TEST ,) 32768 1950 1950 1.04
(L2S TEST ,) 32768 1982 1982 1.02
(L2S-4 TEST ,) 16384 1014 2028 1.00
--------------------------------------------------------------------------------
_$ (progn (setq test nil) (repeat 5 (setq test (cons "test" test))) (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ","))))
Benchmarking ..... done for 16384 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(L2S-3 TEST ,) 16384 1014 1014 1.03
(L2S-2 TEST ,) 16384 1015 1015 1.03
(L2S TEST ,) 16384 1045 1045 1.00
(STRINGLIST->TOKENSTRING TEST ,) 16384 1046 1046 1.00
(L2S-4 TEST ,) 16384 1046 1046 1.00
--------------------------------------------------------------------------------
_$ (progn (setq test nil) (repeat 20 (setq test (cons "test" test))) (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ","))))
Benchmarking ..... done for 16384 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(L2S-4 TEST ,) 16384 1294 1294 1.19
(STRINGLIST->TOKENSTRING TEST ,) 16384 1357 1357 1.14
(L2S-3 TEST ,) 16384 1434 1434 1.08
(L2S-2 TEST ,) 16384 1467 1467 1.05
(L2S TEST ,) 16384 1544 1544 1.00
--------------------------------------------------------------------------------
_$ (progn (setq test nil) (repeat 60 (setq test (cons "test" test))) (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ","))))
Benchmarking ..... done for 8192 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(L2S-4 TEST ,) 8192 1138 1138 1.30
(STRINGLIST->TOKENSTRING TEST ,) 8192 1154 1154 1.28
(L2S-3 TEST ,) 8192 1280 1280 1.16
(L2S-2 TEST ,) 8192 1343 1343 1.10
(L2S TEST ,) 8192 1482 1482 1.00
--------------------------------------------------------------------------------
_$ (progn (setq test nil) (repeat 1000 (setq test (cons "test" test))) (quickbench '((stringlist->tokenstring test ",") (l2s test ",") (l2s-2 test ",") (l2s-3 test ",") (l2s-4 test ","))))
Benchmarking ..... done for 1024 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(STRINGLIST->TOKENSTRING TEST ,) 1024 1574 1574 1.55
(L2S-4 TEST ,) 1024 1748 1748 1.39
(L2S-3 TEST ,) 1024 2010 2010 1.21
(L2S-2 TEST ,) 512 1107 2214 1.10
(L2S TEST ,) 512 1216 2432 1.00
--------------------------------------------------------------------------------