(princ "\nPlease select 3Dface triangle:")
(setq ss1 (ssget ))
(setq n 0)
(repeat (sslength ss1)
(setq ent (ssname n ss1))
........
(setq n (1+ n))
)
(if (setq ss1 (ssget ))
(repeat (setq n (sslength ss1))
(setq ent (ssname ss1 (setq n (1- n))))
........
)
)
(mapcar (function (lambda (dim)
AND compile your code!!!!!! (setq i -1)
(while (setq ename (ssname ss (setq i (1+ i))))
(setq result (cons ename result))
)
I believe the while loop is faster than repeat.
Testing on selection set of 1000 entities
Benchmarking ....... done for 1024 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_WHILEPROP) 1024 1029 1029 168.80
(SSTEST_REPEATPROP) 1024 1185 1185 146.58
(SSTEST_VLA) 256 1902 7608 22.83
(SSTEST_WHILEDXF) 128 1857 14856 11.69
(SSTEST_REPEATDXF) 128 1919 15352 11.31
(SSTEST_VLA_PROP) 16 1077 68928 2.52
(SSTEST_VLA_DXF) 8 1357 173696 1.00
--------------------------------------------------------------------------------
And compiledTesting on selection set of 1000 entities
Benchmarking ....... done for 2048 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_REPEATPROP) 2048 1280 1280 284.00
(SSTEST_WHILEPROP) 2048 1577 1577 230.51
(SSTEST_VLA) 256 1888 15104 24.07
(SSTEST_WHILEDXF) 128 1794 28704 12.66
(SSTEST_REPEATDXF) 128 1809 28944 12.56
(SSTEST_VLA_PROP) 16 1075 137600 2.64
(SSTEST_VLA_DXF) 8 1420 363520 1.00
--------------------------------------------------------------------------------
It doesn't seem as if the difference between repeat & while is significant in comparison to what you actually do inside / outside the loop. As expected the convert from vla-object is simply stupidly slow (even with compiling). Pure VLA is about 2x faster than working with DXF data, but the ename only is 100x faster than that.Testing on selection set of 1000 entities
Benchmarking ....... done for 64 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_WHILEDXF) 64 1202 1202 9.14
(SSTEST_REPEATDXF) 64 1233 1233 8.91
(SSTEST_VLA) 16 1154 4616 2.38
(SSTEST_WHILEPROP) 16 1700 6800 1.62
(SSTEST_REPEATPROP) 16 1701 6804 1.61
(SSTEST_VLA_PROP) 8 1372 10976 1.00
(SSTEST_VLA_DXF) 8 1373 10984 1.00
--------------------------------------------------------------------------------
_$ (vlisp-compile 'st "SelectTest.LSP")
T
_$ (load "SelectTest.FAS")
SSTEST_VLA_PROP
_$ (c:RunSSTest)
Testing on selection set of 1000 entities
Benchmarking ....... done for 128 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_WHILEDXF) 128 1918 1918 11.32
(SSTEST_REPEATDXF) 128 1950 1950 11.13
(SSTEST_VLA) 16 1139 9112 2.38
(SSTEST_REPEATPROP) 16 1606 12848 1.69
(SSTEST_WHILEPROP) 16 1654 13232 1.64
(SSTEST_VLA_DXF) 8 1342 21472 1.01
(SSTEST_VLA_PROP) 8 1357 21712 1.00
--------------------------------------------------------------------------------
See what I mean by it's more important about the internals of the loop than the loop itself? E.g. unexpectedly the dxf actually becomes faster than the vla - by 5x. And the prop becomes stupidly slow - nearly comparable to the converted defuns.
Testing on selection set of 1000 entities
Benchmarking ....... done for 32 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_VLA) 32 1654 1654 27.46
(SSTEST_WHILEDXF) 16 1404 2808 16.18
(SSTEST_REPEATDXF) 16 1420 2840 15.99
(SSTEST_VLA_DXF) 8 1670 6680 6.80
(SSTEST_VLA_PROP) 2 1622 25952 1.75
(SSTEST_REPEATPROP) 2 1747 27952 1.63
(SSTEST_WHILEPROP) 2 2839 45424 1.00
--------------------------------------------------------------------------------
And when compiled it seems more pronouncedTesting on selection set of 1000 entities
Benchmarking ....... done for 16 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_VLA) 16 1060 1060 22.72
(SSTEST_WHILEDXF) 16 2029 2029 11.87
(SSTEST_REPEATDXF) 16 2058 2058 11.70
(SSTEST_VLA_DXF) 4 1279 5116 4.71
(SSTEST_REPEATPROP) 1 1014 16224 1.48
(SSTEST_VLA_PROP) 1 1076 17216 1.40
(SSTEST_WHILEPROP) 2 3011 24088 1.00
--------------------------------------------------------------------------------
It must be that optimized method of generating the list of points.
(defun SSTest_ForeachDXF (/ en ed lst)
(foreach x (ssnamex ss)
(setq lst (cons
((lambda (en)
(list
(cdr (assoc 10 en))
(cdr (assoc 11 en))
(cdr (assoc 12 en))
(cdr (assoc 13 en))
)
)
(entget (cadr x))
)
lst
)
)
)
)
(defun SSTest_MapcarDXF ()
(mapcar
(function
(lambda (x)
((lambda (en)
(list
(cdr (assoc 10 en))
(cdr (assoc 11 en))
(cdr (assoc 12 en))
(cdr (assoc 13 en))
)
)
(entget (cadr x)))
)
)
(ssnamex ss)
)
)
Note the differences in colecting coords... (mapcar (function (lambda (code) (cdr (assoc code ed)))) '(10 11 12 13))
will place my functions at the very bottom benchmark list
UsingCode: [Select](mapcar (function (lambda (code) (cdr (assoc code ed)))) '(10 11 12 13))
will place my functions at the very bottom benchmark list
What are you doing inside the loop? The entget might be where most of the time is wasted. If so could your routine be redesigned not to need entget? I.e. just generate a new list to pass to entmod? Or even use the new properties methods.
Or could your routine be redesigned to use vla-objects? If so then using Method 5 from Lee's samples here (http://www.cadtutor.net/forum/showthread.php?72186-Loop-While&p=493190&viewfull=1#post493190) might be faster.
Perhaps I've overlooked something, but for such a large selection, why not instead just iterate the ActiveSelectionSet Object :??
RM, that was my suggestion.
irnebThanks, fixed that in attached.
Your sstest_vla returns wrong result (you typed cords instead coords...)
Using ssnamex will place the functions at the bottom - ssnamex is incredibly slow ;)Thought so too, though they're not as bad as all that.
Testing on selection set of 1000 entities
Benchmarking ......... done for 32 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
--------------------------------------------------------------------------------
(SSTEST_VLA) 32 1763 1763 22.23
(SSTEST_REPEATDXF) 16 1216 2432 16.12
(SSTEST_WHILEDXF) 16 1217 2434 16.11
(SSTEST_MAPCARDXF) 16 1248 2496 15.71
(SSTEST_FOREACHDXF) 16 1264 2528 15.51
(SSTEST_VLA_DXF) 8 1420 5680 6.90
(SSTEST_REPEATPROP) 2 1279 20464 1.92
(SSTEST_VLA_PROP) 2 1436 22976 1.71
(SSTEST_WHILEPROP) 2 2450 39200 1.00
--------------------------------------------------------------------------------
While the are slower than the normal ssname / vla versions, they're not as bad as the convert / prop versions. But that's because of the internals of the loop itself methinks. I think we've established somewhere else that the ssnamex is slow in comparison to a loop with ssname (if only looking at the selection iteration itself).
(defun c:EXPORT-SURFACE ( / ent ss tmp c nfile start en elst p1 p2 p3 str)
(if (and (setq ent (car (entsel "\nPick 3D Surface >")))
(setq ss (ssget "X" (list (cons 0 "3DFACE")(cons 8 (cdr (assoc 8 (entget ent)))))))
(if tinout
(setq tmp (getfiled "Export 3D Surface to file" tinout "TIN" 1))
(setq tmp (getfiled "Export 3D Surface to file" "" "TIN" 1))
)
)
(progn
(setq tinout tmp c -1 nfile (open tinout "w") start (getvar "DATE"))
(repeat (sslength ss)
(setq en (ssname ss (setq c (1+ c))) elst (entget en))
(setq p1 (cdr (assoc 10 elst)) p2 (cdr (assoc 11 elst)) p3 (cdr (assoc 12 elst)))
(setq str (strcat (rtos (car p1) 2 3) "," (rtos (cadr p1) 2 3) "," (rtos (caddr p1) 2 3) ","
(rtos (car p2) 2 3) "," (rtos (cadr p2) 2 3) "," (rtos (caddr p2) 2 3) ","
(rtos (car p3) 2 3) "," (rtos (cadr p3) 2 3) "," (rtos (caddr p3) 2 3)))
(write-line str nfile)
)
(princ (strcat "\rExport Complete - Elapsed time: " (rtos (* 86400.0 (- (getvar "date") start)) 2 2) " secs."))
(close nfile)
)
)
(princ)
)