Lee Mac Posted June 27, 2012 Posted June 27, 2012 My solution is fastest as it was made by Autodesk for exactly these purposes... my conclusion was that the best thing is to use already predefined functions... Maybe, you don't agree with me, but to me they do the job fine and more important I think faster then any of above proposed codes... (test it and if you disagree reply...) 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: (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. ;; 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 ) (defun ss-union ( lst ) (apply 'vl-cmdf (append '("_.select") lst '(""))) (ssget "_P") ) (acet-ss-union <List of Selection Sets>) The Results: LM:SS-UNION Command: (test 'LM:ss-union) Selection Set Lengths: ---------------------------------------------- Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 ---------------------------------------------- [color=red]LM:SS-UNION time: 94 ms[/color] ---------------------------------------------- SS-UNION 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: [color=red]SS-UNION time: 78 ms[/color] ---------------------------------------------- ACET-SS-UNION 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: [color=red]ACET-SS-UNION time: 94 ms[/color] ---------------------------------------------- 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"). 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-UNION 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 ---------------------------------------------- [color=red]LM:SS-UNION time: 1201 ms[/color] ---------------------------------------------- SS-UNION 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: [color=red]SS-UNION time: 780 ms[/color] ---------------------------------------------- ACET-SS-UNION Command: (test 'acet-ss-union) Selection Set Lengths: ---------------------------------------------- [color=red]Selection Set 1: 100 Selection Set 2: 400 Selection Set 3: 1600 Selection Set 4: 6400 Selection Set 5: 25600 Selection Set 6: 102400[/color] ----------------------------------------------_.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: [color=red]ACET-SS-UNION time: 811 ms[/color] ---------------------------------------------- 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. Quote
pBe Posted June 28, 2012 Posted June 28, 2012 pBe, I've also tried this once on www.augi.com :http://forums.augi.com/showthread.php?138426-sel-sets-subfunctions&p=#1 ..... my conclusion was that the best thing is to use already predefined functions... Maybe, you don't agree with me, but to me they do the job fine and more important I think faster then any of above proposed codes... Thank you for posting the link ,i'm sure the OP will appreciate that. Now as for whats FASTER is not what i'm driving at. But what we can do to help with query the OP posted. This is CAD Tutor after all. Quote
drafter007 Posted June 28, 2012 Author Posted June 28, 2012 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! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.