Author Topic: ( Challenge ) Shortest & Longest Pline  (Read 13333 times)

0 Members and 1 Guest are viewing this topic.

LE3

  • Guest
Re: ( Challenge ) Shortest & Longest Pline
« Reply #30 on: February 06, 2013, 01:29:41 PM »
the best performance, i was able to get using a c# routine is 88msecs on a bylayer sorting

But how fast do the AutoLISP solutions run on your system by comparison?

Will run those tests later and post here and added also the time-it port into c#, to do the compare with the same - but looks like the sw.ElapsedMilliseconds from the var sw = new Stopwatch(); it is basically returning the same timing.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: ( Challenge ) Shortest & Longest Pline
« Reply #31 on: February 06, 2013, 02:52:23 PM »
Here are my results for all 'layer-by-layer' programs posted: ...

What AutoCAD version?

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: ( Challenge ) Shortest & Longest Pline
« Reply #32 on: February 06, 2013, 03:19:08 PM »
Here are my results for all 'layer-by-layer' programs posted: ...
What AutoCAD version?

AutoCAD 2013 / Windows 7 Ultimate 32-bit
Intel Core2 Duo 2.1GHz, 3GB RAM

LE3

  • Guest
Re: ( Challenge ) Shortest & Longest Pline
« Reply #33 on: February 06, 2013, 03:23:06 PM »
got the chance to run this one on one of my old pc's and inside of acad2011:
Quote
Command: (time-it '(c:RemAllButLongest&ShortestByLayer))
Program running time: 125 msecs.

Quote
Command: (time-it '(C:ALE_ShortLongestPLByLyr01))
_.ERASE
Select objects: _ALL 1624 found
Select objects: _R
Remove objects:   8 found, 8 removed, 1616 total
Remove objects:
Command:
Program running time: 375 msecs.

and this one:
Quote
Command: (time-it '(c:testfoo))
Program running time: 157 msecs.

ps> guess it is taking me more time to remove all those stupid numbers on the code rows.... can't do any more testing, it is a lot of waste of time to remove all those numbers on the rows (maybe there is a shortcut to remove them easily... but still no idea why they are needed?)

if possible, please remove those or post code using just the  code /code with the brackets... that's much better - my 2cts.
« Last Edit: February 06, 2013, 03:46:23 PM by LE »

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: ( Challenge ) Shortest & Longest Pline
« Reply #34 on: February 06, 2013, 04:25:39 PM »
ps> guess it is taking me more time to remove all those stupid numbers on the code rows.... can't do any more testing, it is a lot of waste of time to remove all those numbers on the rows (maybe there is a shortcut to remove them easily... but still no idea why they are needed?)

if possible, please remove those or post code using just the  code /code with the brackets... that's much better - my 2cts.

Luis, I believe the line numbers are only copied with IE, they aren't copied for me using FF18.0.2...

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: ( Challenge ) Shortest & Longest Pline
« Reply #35 on: February 06, 2013, 04:28:39 PM »
Here are my results for all 'layer-by-layer' programs posted: ...
What AutoCAD version?

AutoCAD 2013 / Windows 7 Ultimate 32-bit
Intel Core2 Duo 2.1GHz, 3GB RAM
I do not have 2013 on Win 32-bit, can you test this:
Code: [Select]
(defun C:ALE_ShortLongestPLByLyr02 ( / SelSet EntDat Countr EntNam LenVal LyrNam InfLtC InfLtB InfLtG InfLtR)
    (if (setq SelSet (ssget "_X" (list '(0 . "POLYLINE"))))
      (progn
       (acad-push-dbmod) (setvar "HIGHLIGHT" 0)
       (setq
          Countr 0
          EntNam (ssname SelSet 0)
          EntDat (entget EntNam)
          LenVal (vlax-curve-getDistAtParam EntNam (vlax-curve-getEndParam EntNam))
          InfLtB (list EntNam LenVal EntNam LenVal)
          InfLtC InfLtB InfLtG InfLtB InfLtR InfLtB
        )
        (repeat (sslength SelSet)
          (setq
            EntNam (ssname SelSet Countr) EntDat (entget EntNam)
            LenVal (vlax-curve-getDistAtParam EntNam (vlax-curve-getEndParam EntNam))
            LyrNam (cdr (assoc 8 EntDat))
            Countr (1+ Countr)
          )
          (cond
            ( (eq LyrNam "BLUE")
              (cond
                ( (> LenVal (cadddr InfLtB))
                  (setq InfLtB (list (car InfLtB) (cadr InfLtB) EntNam LenVal))
                )
                ( (< LenVal (cadr   InfLtB))
                  (setq InfLtB (list EntNam LenVal (caddr InfLtB) (cadddr InfLtB)))
                )
              )
            )
            ( (eq LyrNam "CYAN")
              (cond
                ( (> LenVal (cadddr InfLtC))
                  (setq InfLtC (list (car InfLtC) (cadr InfLtC) EntNam LenVal))
                )
                ( (< LenVal (cadr   InfLtC))
                  (setq InfLtC (list EntNam LenVal (caddr InfLtC) (cadddr InfLtC)))
                )
              )
            )
            ( (eq LyrNam "GREEN")
              (cond
                ( (> LenVal (cadddr InfLtG))
                  (setq InfLtG (list (car InfLtG) (cadr InfLtG) EntNam LenVal))
                )
                ( (< LenVal (cadr   InfLtG))
                  (setq InfLtG (list EntNam LenVal (caddr InfLtG) (cadddr InfLtG)))
                )
              )
            )
            ( (eq LyrNam "RED")
              (cond
                ( (> LenVal (cadddr InfLtR))
                  (setq InfLtR (list (car InfLtR) (cadr InfLtR) EntNam LenVal))
                )
                ( (< LenVal (cadr   InfLtR))
                  (setq InfLtR (list EntNam LenVal (caddr InfLtR) (cadddr InfLtR)))
                )
              )
            )
          )
        )
      )
    )
   (command "_.ERASE" SelSet "")
   (foreach ForElm (list InfLtC InfLtB InfLtG InfLtR)
     (entdel (car ForElm)) (entdel (caddr ForElm))
   )
)

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: ( Challenge ) Shortest & Longest Pline
« Reply #36 on: February 06, 2013, 04:29:26 PM »
ps> guess it is taking me more time to remove all those stupid numbers on the code rows.... can't do any more testing, it is a lot of waste of time to remove all those numbers on the rows (maybe there is a shortcut to remove them easily... but still no idea why they are needed?)

if possible, please remove those or post code using just the  code /code with the brackets... that's much better - my 2cts.

Luis, I believe the line numbers are only copied with IE, they aren't copied for me using FF18.0.2...

Me too.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: ( Challenge ) Shortest & Longest Pline
« Reply #37 on: February 06, 2013, 04:39:05 PM »
Quote
... test this: ...
Maybe with command-s is a little bit faster:
(command-s "_.ERASE" SelSet "")

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: ( Challenge ) Shortest & Longest Pline
« Reply #38 on: February 06, 2013, 10:32:38 PM »
if possible, please remove those or post code using just the  code /code with the brackets... that's much better - my 2cts.
The numbers don't copy with any other browser but IE (not FF/Chrome/Opera).

A trick you can do if you're stuck using IE (IMO the worst browser there is - this being one of the reasons): click the quote button, then select & copy the code from the edit box. That should remove the numbers.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: ( Challenge ) Shortest & Longest Pline
« Reply #39 on: February 07, 2013, 12:22:41 AM »
Could the following modifications perhaps shave off a few millisecs?

Code: [Select]
(defun c:RemAllButLongest&ShortestByLayerLeeMacMod < ... >
(C:REMALLBUTLONGEST&SHORTESTBYLAYERLEEMACMOD) - 63 msecs.   :-)

Your computer is way faster than mine  :-D

What was your time?
My times vary.
Code: [Select]
Command: (time-it '(c:RemAllButLongest&ShortestByLayerLeeMacMod))

Program running time: 46 msecs.

Command: _.undo Current settings: Auto = On, Control = All, Combine = Yes
Enter the number of operations to undo or [Auto/Control/BEgin/End/Mark/Back]
<1>: 1
Everything has been undone

Command: (time-it '(c:RemAllButLongest&ShortestByLayerLeeMacMod))

Program running time: 31 msecs.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

pBe

  • Bull Frog
  • Posts: 402
Re: ( Challenge ) Shortest & Longest Pline
« Reply #40 on: February 07, 2013, 01:15:03 AM »
......

A trick you can do if you're stuck using IE (IMO the worst browser there is - this being one of the reasons): click the quote button, then select & copy the code from the edit box. That should remove the numbers.


Exactly, I even went as far as writing a code to remove those leading "numbers" but then i trashed it and settled with Chrome.  ;D


EDIT: found the code


Code - Auto/Visual Lisp: [Select]
  1.  
  2. (Defun c:remlead (/ opf full code a str i where recode)
  3.   (if (setq opf (getfiled "Select Text file:" "" "txt" 16))
  4.     (progn
  5.       (Setq FULL nil
  6.             code (open opf "r")
  7.       )
  8.       (while (setq a (read-line code))
  9.         (if (not (eq "" a))
  10.           (setq FULL (cons a FULL))
  11.         )
  12.       )
  13.       (close code)
  14.       (Setq str   (Car full)
  15.             i     1
  16.             where 0
  17.       )
  18.       (while (setq where (vl-string-search
  19.                            (setq this (strcat (itoa i) "."))
  20.                            str
  21.                            where
  22.                          )
  23.              )
  24.         (if
  25.           (not
  26.             (wcmatch (substr str (1+ where) (1+ (strlen this))) "*.#*")
  27.           )
  28.            (setq str (vl-string-subst "" this str where)
  29.                  i   (1+ i)
  30.            )
  31.            (setq where (1+ where))
  32.         )
  33.       )
  34.       (setq recode (open opf "w"))
  35.       (write-line str recode)
  36.       (close recode)
  37.     )
  38.   )
  39.   (princ)
  40. )
  41.  



« Last Edit: February 07, 2013, 02:17:48 AM by pBe »

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: ( Challenge ) Shortest & Longest Pline
« Reply #41 on: February 07, 2013, 03:18:09 AM »
My last shot:
Code: [Select]
(defun C:ALE_ShortLongestPLByLyr03 ( / SelSet EntDat Countr EntNam LenVal LyrNam TmpLst InfLst)
    (if (setq Countr 0 SelSet (ssget "_X" (list '(0 . "POLYLINE"))))
      (progn
        (setvar "HIGHLIGHT" 0)
        (repeat (sslength SelSet)
          (setq
            EntNam (ssname SelSet Countr) EntDat (entget EntNam)
            LenVal (vlax-curve-getDistAtParam EntNam (vlax-curve-getEndParam EntNam))
            LyrNam (cdr (assoc 8 EntDat))
            Countr (1+ Countr)
          )
          (cond
            ( (not (setq TmpLst (assoc LyrNam InfLst)))
              (setq InfLst (cons (list LyrNam EntNam LenVal EntNam LenVal) InfLst))
            )
            ( (> LenVal (nth 4 TmpLst))
              (setq InfLst (subst (list (car TmpLst) (cadr TmpLst) (caddr  TmpLst)  EntNam LenVal) TmpLst  InfLst))
            )
            ( (< LenVal (caddr TmpLst))
              (setq InfLst (subst (list (car TmpLst) EntNam LenVal (cadddr TmpLst) (nth 4 TmpLst)) TmpLst  InfLst))
            )
          )
        )
      )
    )
   (command "_.ERASE" SelSet "")
   (foreach ForElm InfLst (entdel (cadr ForElm)) (entdel (cadddr ForElm)))
)

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: ( Challenge ) Shortest & Longest Pline
« Reply #42 on: February 07, 2013, 07:03:30 AM »
I'm not too sure which would be faster:
  • sending a selection set to the erase command
  • entdel each entity in turn
  • vla-Delete each entity
  • vla-Erase a vla selection set (probably this one, but then the rest of the code doesn't perform too well)
I think the use of entdel to unerase the entities should be a slight bit faster, since even sending a remove to the command is still adjusting a selection set (even though it's inside the ObjectARX of the erase command).

But  :| we're all actually missing Mark's request from post #7: Not using any vlax methods. Thus it means stuck with entget (since from a previous test of mine) the new getpropertyvalue function is even slower than using entget (I think it might be because it's implemented in DotNet, which isn't the fastest already, and also needs converting to-and-from DotNet object types): http://www.theswamp.org/index.php?topic=43304.msg485508#msg485508

Thus far I've not seen any other codes performing this without vlax (at least once). Anyone have an idea to speed up my original version from post #9, or do it through some other way? It should be possible to speed it up quite a lot by only worrying about 3d polylines specific to this thread - unlike my code which is calculating even bulged vectors.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: ( Challenge ) Shortest & Longest Pline
« Reply #43 on: February 07, 2013, 07:31:59 AM »
But  :| we're all actually missing Mark's request from post #7: Not using any vlax methods.

Much slower  :|
Code: [Select]
(defun LM:LongShortPoly ( / e1 e2 el in le ll ln p1 p2 se sl ss )
    (foreach la '((8 . "BLUE") (8 . "CYAN") (8 . "GREEN") (8 . "RED"))
        (setq ll -1.0  le nil
              sl 1e308 se nil
        )
        (if (setq ss (ssget "_X" (list '(0 . "POLYLINE") la)))
            (progn
                (repeat (setq in (sslength ss))
                    (setq e1 (ssname ss (setq in (1- in)))
                          e2 (entnext e1)
                          p1 (cdr (assoc 10 (entget e2)))
                          e2 (entnext e2)
                          el (entget  e2)
                          ln 0.0
                    )
                    (while (= "VERTEX" (cdr (assoc 0 el)))
                        (setq p2 (cdr (assoc 10 el))
                              ln (+ ln (distance p1 p2))
                              e2 (entnext e2)
                              el (entget  e2)
                              p1 p2
                        )
                    )
                    (if (< ll ln)
                        (setq ll ln le e1)
                    )
                    (if (< ln sl)
                        (setq sl ln se e1)
                    )
                    (entdel e1)
                )
                (entdel le)
                (entdel se)
            )
        )
    )
    (princ)
)

Code: [Select]
(time-it '(LM:LongShortPoly))
Program running time: 2324 msecs.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: ( Challenge ) Shortest & Longest Pline
« Reply #44 on: February 07, 2013, 08:11:02 AM »
I'm not too sure which would be faster:
  • sending a selection set to the erase command
  • entdel each entity in turn
  • vla-Delete each entity
  • vla-Erase a vla selection set (probably this one, but then the rest of the code doesn't perform too well)
<clip>
IMHO vla-Erase a vla selection set is slower.
The real problem is to test it:
Code: [Select]
;no vlax-curve-...
(defun C:ALE_ShortLongestPLByLyr05 ( / VlaObj SelSet EntDat Countr EntNam LenVal LyrNam TmpLst InfLst)
    (if (setq Countr 0 SelSet (ssget "_X" (list '(0 . "POLYLINE"))))
      (progn
        (setvar "HIGHLIGHT" 0)
        (repeat (sslength SelSet)
          (setq
            EntNam (ssname SelSet Countr) EntDat (entget EntNam)
            VlaObj (vlax-ename->vla-object EntNam)
            LenVal (vla-get-length VlaObj)
            LyrNam (cdr (assoc 8 EntDat))
            Countr (1+ Countr)
          )
          (cond
            ( (not (setq TmpLst (assoc LyrNam InfLst)))
              (setq InfLst (cons (list LyrNam EntNam LenVal EntNam LenVal) InfLst))
            )
            ( (> LenVal (nth 4 TmpLst))
              (setq InfLst (subst (list (car TmpLst) (cadr TmpLst) (caddr  TmpLst)  EntNam LenVal) TmpLst  InfLst))
            )
            ( (< LenVal (caddr TmpLst))
              (setq InfLst (subst (list (car TmpLst) EntNam LenVal (cadddr TmpLst) (nth 4 TmpLst)) TmpLst  InfLst))
            )
          )
        )
      )
    )
   (command "_.ERASE" SelSet "")
   (foreach ForElm InfLst (entdel (cadr ForElm)) (entdel (cadddr ForElm)))
)

(repeat 10
(time-it '(C:ALE_ShortLongestPLByLyr05))
(command "_.OOPS")
(gc)
)
Program running time: 936 msecs.
Program running time: 406 msecs.
Program running time: 593 msecs.
Program running time: 390 msecs.
Program running time: 312 msecs.
Program running time: 328 msecs.
Program running time: 312 msecs.
Program running time: 406 msecs.
Program running time: 312 msecs.
Program running time: 312 msecs.