Registered forum members do not see this ad.
I would certainly disagree.
Many of the acet-* functions only appear faster because they are 'compiled' and hence internally linked & optimised. Disregarding the fact that one cannot be guaranteed that all users will have Express Tools' installed and loaded, (which in itself is a good enough reason in many cases to avoid using such functions in applications, especially those which you plan to distribute), in my opinion many of the Express Tools' functions are poorly written.
To somewhat explain the results of your 'research', I'm not surprised that you found your code to be far slower, since your 'ss=s1+s2' is needlessly complicated and rather inefficient.
Consider the following demonstration:
Test Code:
Code:(defun test ( func / et i lst ss st ) (while (setq ss (ssget '((0 . "POINT")))) (setq lst (cons ss lst)) ) (if lst (progn (setq i 0) (princ "\nSelection Set Lengths: ") (princ "\n----------------------------------------------") (foreach x lst (princ (strcat "\nSelection Set " (itoa (setq i (1+ i))) ": " (itoa (sslength x)))) ) (princ "\n----------------------------------------------") (setq fn (eval func)) (setq st (getvar 'millisecs)) (fn lst) (setq et (getvar 'millisecs)) (princ (strcat "\n" (vl-symbol-name func) " time: " (itoa (- et st)) " ms")) (princ "\n----------------------------------------------") ) ) (princ) )
The Test:
Return the union of a list of four Selection Sets of Point entities with sizes 6400, 1600, 400, 100.
The Functions:
To provide a fair test, the functions ss-union and LM:ss-union were compiled to a .fas file.
Code:;; Selection Set Union - Lee Mac ;; Returns the union of a list of Selection Sets (defun LM:ss-union ( lst / i out ) (setq lst (vl-sort lst '(lambda ( a b ) (> (sslength a) (sslength b)))) out (car lst) ) (foreach ss (cdr lst) (repeat (setq i (sslength ss)) (ssadd (ssname ss (setq i (1- i))) out) ) ) out )Code:(defun ss-union ( lst ) (apply 'vl-cmdf (append '("_.select") lst '(""))) (ssget "_P") )Code:(acet-ss-union <List of Selection Sets>)
The Results:
LM:SS-UNIONSS-UNIONCode:Command: (test 'LM:ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 ---------------------------------------------- LM:SS-UNION time: 94 ms ----------------------------------------------ACET-SS-UNIONCode:Command: (test 'ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 ----------------------------------------------_.select Select objects: 100 found Select objects: 400 found, 500 total Select objects: 1600 found, 2100 total Select objects: 6400 found, 8500 total Select objects: Command: SS-UNION time: 78 ms ----------------------------------------------Notice from the above output that the acet-ss-union function uses the same crude method as my ss-union function, by a call to the 'Select' command, however, the difference in performance is because the acet-ss-union function then calls the 'Select' command a second time to return the set, rather than using the more efficient (ssget "_P").Code:Command: (test 'acet-ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 ----------------------------------------------_.SELECT Select objects: 100 found Select objects: 400 found, 500 total Select objects: 1600 found, 2100 total Select objects: 6400 found, 8500 total Select objects: Command: _.SELECT Select objects: 100 found Select objects: Command: ACET-SS-UNION time: 94 ms ----------------------------------------------
Of course, the methods involving a call to the 'Select' command will inevitably always be faster than iterating over the Selection Set in LISP, since any and all iteration of the set is performed by the (presumably) Arx module that operates the 'Select' command.
However, this difference is only slight, even for very large (and possibly rare) unions, as demonstrated by the following merge of six Selection Sets with sizes 102400, 25600, 6400, 1600, 400 & 100:
LM:SS-UNIONSS-UNIONCode:Command: (test 'LM:ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 Selection Set 5: 25600 Selection Set 6: 102400 ---------------------------------------------- LM:SS-UNION time: 1201 ms ----------------------------------------------
ACET-SS-UNIONCode:Command: (test 'ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 Selection Set 5: 25600 Selection Set 6: 102400 ----------------------------------------------_.select Select objects: 100 found Select objects: 400 found, 500 total Select objects: 1600 found, 2100 total Select objects: 6400 found, 8500 total Select objects: 25600 found, 34100 total Select objects: 102400 found, 136500 total Select objects: Command: SS-UNION time: 780 ms ----------------------------------------------I would personally argue that this difference is negligible given the aforementioned drawbacks of using the acet-* functions, and furthermore the necessity to modify the CMDECHO System Variable for a 'clean' output following a call to the 'Select' command.Code:Command: (test 'acet-ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 Selection Set 5: 25600 Selection Set 6: 102400 ----------------------------------------------_.SELECT Select objects: 100 found Select objects: 400 found, 500 total Select objects: 1600 found, 2100 total Select objects: 6400 found, 8500 total Select objects: 25600 found, 34100 total Select objects: 102400 found, 136500 total Select objects: Command: _.SELECT Select objects: 100 found Select objects: Command: ACET-SS-UNION time: 811 ms ----------------------------------------------
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
Registered forum members do not see this ad.
Perfect! this is what i want to see here - discusions, argues, ideeas... anyhow, i'm the best lisper in the world!
Thanks to all guys!
Bookmarks