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
Copy file name to clipboardExpand all lines: README.org
+69-1Lines changed: 69 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -351,7 +351,75 @@ As is usually the case, the =cl-loop= macro expands to the most efficient code,
351
351
352
352
However, in some cases =cl-loop= may expand to code which uses =nconc=, which, as the benchmark shows, is much slower. In that case, you may write the loop without =cl-loop= to avoid using =nconc=.
353
353
354
-
**** Filtering a list
354
+
**** Diffing two lists :lists:
355
+
356
+
As expected, =seq-difference= is the slowest, because it's a generic function that dispatches based on the types of its arguments, which is relatively slow in Emacs. And it's not surprising that =cl-nset-difference= is generally slightly faster than =cl-set-difference=, since it's destructive.
357
+
358
+
However, it is surprising how much faster =-difference= is than =cl-nset-difference=.
359
+
360
+
It's also nonintuitive that =-difference= suffers a large performance penalty by binding =-compare-fn= (the equivalent of the =:test= argument to =cl-set-difference=): while one might expect that setting it to =string== would give a slight performance increase, it's actually faster to let =-difference= use its default, =equal=.
361
+
362
+
Note that since this benchmark compares lists of strings, =cl-nset-difference= requires setting the =:test= argument, since it uses =eql= by default, which does not work for comparing strings.
363
+
364
+
#+BEGIN_SRC elisp :exports both :eval no-export
365
+
(defmacro test/set-lists ()
366
+
`(setf list1 (cl-loop for i from 0 below 1000
367
+
collect (number-to-string i))
368
+
list2 (cl-loop for i from 500 below 1500
369
+
collect (number-to-string i))))
370
+
371
+
(let (list1 list2)
372
+
(bench-multi-lexical :times 10 :ensure-equal t
373
+
:forms (("-difference"
374
+
(progn
375
+
(test/set-lists)
376
+
(-difference list1 list2)))
377
+
("-difference string="
378
+
(progn
379
+
;; This is much slower because of the way `-contains?'
0 commit comments