Note that the performance difference between the functions is highly dependent upon the combination of list length and number of pairs; for example, in the test case for all benchmarking performed in this thread we have used:
l1 '(1 2 3 4 5 6 7)
l2 '("a" "b" "c" "d" "e")
n 200
)
In Irneb's function, following the exponential doubling operation, the initial lists have lengths
224 and
320 respectively (
7x25 |
5x26), meaning that only
24 items need be removed after the
mapcar pairing.
Conversely, in my
pairup7 code, after the compounding of the restricting list
'l3',
72 items need to be added to obtain the correct length.
If we now skew these parameters, so that the lists both have length
2, and the number of pairs is
257, Irneb's function needs to remove
255 items from the resulting paired list (
29 - 257); whereas, my
pairup7 function only need add
1 item following the successive doubling.
As expected, here are the results:
_$ (benchmark '((pairup7 '(1 2) '("a" "b") 257) (pairlists2 '(1 2) '("a" "b") 257)))
Benchmarking ...............Elapsed milliseconds / relative speed for 4096 iteration(s):
(PAIRUP7
(QUOTE (1 2)) (QUOTE ("a" ....
).....
1560 / 1.39 <fastest
> (PAIRLISTS2
(QUOTE (1 2)) (QUOTE ("a"..
).....
2168 / 1 <slowest
>