Author Topic: SelectionSet To Entity-names-List  (Read 1316 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
SelectionSet To Entity-names-List
« on: October 26, 2020, 02:11:56 PM »
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:
Code: [Select]
(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))
  )
)
Code: [Select]
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>


Stefan

  • Bull Frog
  • Posts: 319
  • The most I miss IRL is the Undo button
Re: SelectionSet To Entity-names-List
« Reply #1 on: October 26, 2020, 02:34:14 PM »
Take a look here
https://www.theswamp.org/index.php?topic=43304.0

If you are looking for speed, ssnamex is not favorite.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: SelectionSet To Entity-names-List
« Reply #2 on: October 26, 2020, 04:23:14 PM »
Take a look here
https://www.theswamp.org/index.php?topic=43304.0

If you are looking for speed, ssnamex is not favorite.
I have almost certainly read that discussion, my memory is beginning to show tangible signs of gaps…  :whistling: