Author Topic: A diversion for the recreationally challenged.  (Read 35527 times)

0 Members and 1 Guest are viewing this topic.

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: A diversion for the recreationally challenged.
« Reply #45 on: November 06, 2010, 03:30:51 PM »
Glad to help.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

gskelly

  • Newt
  • Posts: 185
Re: A diversion for the recreationally challenged.
« Reply #46 on: November 06, 2010, 03:47:27 PM »
Is the lambda stuff compatible with other drafting programs such as Bricscad?

There should be no problem with lambda in Bricscad. Just did a quick copy/paste of Lee's swamp-ss-zoom-extents and it appears (visually) to work as expected in Bricscad v10. (I did not actually check the values of the extents returned).

Bricscad v12

ronjonp

  • Needs a day job
  • Posts: 7529
Re: A diversion for the recreationally challenged.
« Reply #47 on: November 06, 2010, 09:52:04 PM »
Is the lambda stuff compatible with other drafting programs such as Bricscad?

There should be no problem with lambda in Bricscad. Just did a quick copy/paste of Lee's swamp-ss-zoom-extents and it appears (visually) to work as expected in Bricscad v10. (I did not actually check the values of the extents returned).



Good to know :)  I wonder why while isn't used more since it seems to usually be the winner in speed "challenges".

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: A diversion for the recreationally challenged.
« Reply #48 on: November 06, 2010, 09:55:59 PM »
Is the lambda stuff compatible with other drafting programs such as Bricscad?

There should be no problem with lambda in Bricscad. Just did a quick copy/paste of Lee's swamp-ss-zoom-extents and it appears (visually) to work as expected in Bricscad v10. (I did not actually check the values of the extents returned).



Good to know :)  I wonder why while isn't used more since it seems to usually be the winner in speed "challenges".
I thought repeat was faster than while.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

ronjonp

  • Needs a day job
  • Posts: 7529
Re: A diversion for the recreationally challenged.
« Reply #49 on: November 06, 2010, 10:06:42 PM »
Is the lambda stuff compatible with other drafting programs such as Bricscad?

There should be no problem with lambda in Bricscad. Just did a quick copy/paste of Lee's swamp-ss-zoom-extents and it appears (visually) to work as expected in Bricscad v10. (I did not actually check the values of the extents returned).



Good to know :)  I wonder why while isn't used more since it seems to usually be the winner in speed "challenges".
I thought repeat was faster than while.

Is it? :? I could be waaaaaay off again  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Re: A diversion for the recreationally challenged.
« Reply #50 on: November 07, 2010, 12:12:53 AM »
hmmm ... logic suggests a while loop would be slower because tests are evaluated at the lisp (interpreted) level, whereas in a repeat loop they're evaluated at the executable level; most likely using a register for the counter value. Could be over thinking it tho, been a long day.
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

JohnK

  • Administrator
  • Seagull
  • Posts: 10648
Re: A diversion for the recreationally challenged.
« Reply #51 on: November 07, 2010, 01:07:34 AM »
repeat, foreach, while. In that order.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: A diversion for the recreationally challenged.
« Reply #52 on: November 07, 2010, 07:29:28 AM »
Hi,

As Michael said, logicaly repeat sould be faster than while, but it appears to me that most of the time while seems to be faster.
Anyway, a while statement speed depends on what is evaluated in the conditional expression.

Here's an example with three implementations of the classical ss2lst routine which returns a list of ename from a selection set.
The first one (ss2lst_repeat) uses repeat with the length of the selection set.
The second one (ss2lst_while1) uses while the same way as repeat evaluating a counter
The third one (ss2lst_while2) uses while in an optimised way: evaluating (ssname ss n) as condition, this have to be evaluated in every case.
I don't include foreach, neither mapcar, which only operate on lists.

Code: [Select]
(defun ss2lst_repeat (ss / n lst)
  (repeat (setq n (sslength ss))
    (setq lst (cons (ssname ss (setq n (1- n))) lst))
  )
  lst
)

(defun ss2lst_while1 (ss / n lst)
  (setq n (sslength ss))
  (while (< 0 n)
    (setq lst (cons (ssname ss (setq n (1- n))) lst))
  )
  lst
)

(defun ss2lst_while2 (ss / n ent lst)
  (setq n -1)
  (while (setq ent (ssname ss (setq n (1+ n))))
    (setq lst (cons ent lst))
  )
  (reverse lst)
)

Quote
_$ (sslength (setq ss (ssget)))
10000
_$ (benchmark '((ss2lst_repeat ss) (ss2lst_while1 ss) (ss2lst_while2 ss)))
Benchmarking ..........Elapsed milliseconds / relative speed for 128 iteration(s):

    (SS2LST_WHILE2 SS).....1060 / 1.35 <fastest>
    (SS2LST_WHILE1 SS).....1248 / 1.15
    (SS2LST_REPEAT SS).....1435 / 1.00 <slowest>
Speaking English as a French Frog

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: A diversion for the recreationally challenged.
« Reply #53 on: November 08, 2010, 03:44:21 AM »
Code: [Select]
(sslength (setq ss (ssget "_x")))
(benchmark '((ss2lst_repeat ss) (ss2lst_while1 ss)(ss2lst_while2 ss) (ACET-SS-TO-LIST ss)))

Code: [Select]
_$

10000
_$
Benchmarking ...........Elapsed milliseconds / relative speed for 256 iteration(s):

    (ACET-SS-TO-LIST SS).....1389 / 1.85 <fastest>
    (SS2LST_WHILE2 SS).......1888 / 1.36
    (SS2LST_WHILE1 SS).......2278 / 1.13
    (SS2LST_REPEAT SS).......2574 / 1 <slowest>

 
_$

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: A diversion for the recreationally challenged.
« Reply #54 on: November 08, 2010, 03:51:53 AM »

 :-D

(ACET-SS-TO-LIST SS).....1389 / 1.85 <fastest>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: A diversion for the recreationally challenged.
« Reply #55 on: November 08, 2010, 03:55:03 AM »

 :-D

(ACET-SS-TO-LIST SS).....1389 / 1.85 <fastest>


It is easy to explain - the program is already compiled versions of the...

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: A diversion for the recreationally challenged.
« Reply #56 on: November 08, 2010, 04:08:31 AM »
after compilation:
Code: [Select]
(defun c:test (/ ss)
 (sslength (setq ss (ssget "_x")))
 (benchmark
  '((ss2lst_repeat ss) (ss2lst_while1 ss) (ss2lst_while2 ss) (ACET-SS-TO-LIST ss))
 )
 (princ)
)

Code: [Select]
(LOAD "C:/Users/EElpanov/Desktop/test/test.VLX") nil
Elapsed milliseconds / relative speed for 512 iteration(s):
    (SS2LST_REPEAT SS).......1155 / 2.42 <fastest>
    (SS2LST_WHILE1 SS).......1170 / 2.39
    (SS2LST_WHILE2 SS).......1389 / 2.01
    (ACET-SS-TO-LIST SS).....2792 / 1 <slowest>

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: A diversion for the recreationally challenged.
« Reply #57 on: November 08, 2010, 04:23:29 AM »

That sounds better :)

The ACET-SS-TO-LIST jumps through a lot of hoops
Checks if ss
checks (EQUAL (TYPE SS) PICKSET)
checks (> (SSLENGTH SS) 0)

Then runs a repeat on the ... (SSNAME SS n)

cons a list

Reverse the list when finished.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: A diversion for the recreationally challenged.
« Reply #58 on: November 08, 2010, 07:13:28 AM »
Wow - I didn't realise compilation made that much of a difference....

ronjonp

  • Needs a day job
  • Posts: 7529
Re: A diversion for the recreationally challenged.
« Reply #59 on: November 08, 2010, 08:41:32 AM »
So we can say while beats repeat except after c and when compiled?  :-D

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC