I've seen lately the use of this form: "(vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))" to get a list of entity names from a selection and I wanted to test if it's efficient and I was surprised with the results:
(defun Tests_Repeat_Ssname (ss / i l)
(repeat (setq i (sslength ss))
(setq l (cons (ssname ss (setq i (1- i))) l))
)
)
(defun Tests_Foreach_Ssnamex (ss / l)
(foreach e (ssnamex ss)
(and
(= 'ename (type (cadr e)))
(setq l (cons (cadr e) l))
)
)
l
)
(defun Tests_Foreach_Ssnamex2 (ss / l)
(foreach e (ssnamex ss)
(or
(minusp (car e))
(setq l (cons (cadr e) l))
)
)
l
)
(defun Tests_Removeif_Ssnamex (ss)
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex ss))
)
)
Benchmark.lsp | © 2005 Michael Puckett | All Rights Reserved
(length SS1) => 1919
selection By All + 5 crossing window + 6 single Pick
Elapsed milliseconds / relative speed for 2048 iteration(s):
(TESTS_REPEAT_SSNAME SS1).........1906 / 7.28 <fastest>
(TESTS_REMOVEIF_SSNAMEX SS1).....11125 / 1.25
(TESTS_FOREACH_SSNAMEX2 SS1).....12609 / 1.1
(TESTS_FOREACH_SSNAMEX SS1)......13875 / 1 <slowest>
; ---------------------------------------------------------
(length SS1) => 1919
selection By All
Elapsed milliseconds / relative speed for 2048 iteration(s):
(TESTS_REPEAT_SSNAME SS1).........1890 / 6.87 <fastest>
(TESTS_REMOVEIF_SSNAMEX SS1).....10203 / 1.27
(TESTS_FOREACH_SSNAMEX2 SS1).....11703 / 1.11
(TESTS_FOREACH_SSNAMEX SS1)......12985 / 1 <slowest>