Author Topic: list comparison  (Read 11031 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
list comparison
« Reply #30 on: July 11, 2005, 12:08:57 PM »
Why not use this? or am I missing something?

Code: [Select]

(vl-remove-if '(lambda (i) (vl-position i li-c)) li-m)

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
list comparison
« Reply #31 on: July 11, 2005, 12:17:37 PM »
Yes daron, your right. great catches. But yes, I did just slap it together. *blush* I typed it all on command line and just tested it there. Sorry man.

I still havent made my test to see what is faster -ie mapcar, foreach, vl-for.., while, etc. I would like to do some testing to see the speed of these.  ...I'm almost positive that mapcar is recursive in nature and i'd be willing to bet that foreach is not. Anyways im just babbling on here.

Thanx for the catches.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
list comparison
« Reply #32 on: July 11, 2005, 12:25:27 PM »
Quote from: LE
Why not use this? or am I missing something?

Code: [Select]

(vl-remove-if '(lambda (i) (vl-position i li-c)) li-m)


Oho, good one! ...Nope dosnet look to me like your missing a thing.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

daron

  • Guest
list comparison
« Reply #33 on: July 11, 2005, 01:16:45 PM »
Quote from: CAB
As for "proper use and handling of variables" I haven't a clue what you mean.
Perhaps a link to that thread or further explanation.

Salt from my own wound. Also, "proper use..." is poor wording on my part. I don't mean to imply that you shouldn't do it that way. Who am I to say how something should or shouldn't be done. I was only wanting to point out that it might be better left as a collected variable only once and not have to reset that one each time. Very similar in nature to having the (apply 'append ...) run each time you run through each item in the test list I would think. Setting or running it once seems to be the most logical way to do it for me.

Oh, Luis, I've wanted to use vl-remove-if as it seeems it would work, but I've got some other things to think about. It appears that my company might be switching to Intellicad and I'm not sure how up to par ICAD is in the VL- functions, so I'm trying to code so I don't have to rework it if(when) that happens. I'm hoping it doesn't, but I've got to be on guard.

LE

  • Guest
list comparison
« Reply #34 on: July 11, 2005, 01:27:53 PM »
Quote from: daron

Oh, Luis, I've wanted to use vl-remove-if as it seeems it would work, but I've got some other things to think about. It appears that my company might be switching to Intellicad and I'm not sure how up to par ICAD is in the VL- functions, so I'm trying to code so I don't have to rework it if(when) that happens. I'm hoping it doesn't, but I've got to be on guard.


OK... 10-4

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #35 on: July 11, 2005, 03:18:52 PM »
Time trials:
I can not account for the disparity in the results.
Perhaps an interrupt on my computer system?
Command: test
Elapsed time: 1.112000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.082000 seconds for rip-n-flip1
Elapsed time: 1.142000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.042000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.042000 seconds for rip-n-flip1
Elapsed time: 1.122000 seconds for rip-n-flip2
Command:
Command: test

Elapsed time: 1.062000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.152000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.041000 seconds for rip-n-flip1
Elapsed time: 1.072000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.052000 seconds for rip-n-flip2
Command:
Command: test
Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.051000 seconds for rip-n-flip2
Command: test

Elapsed time: 1.101000 seconds for rip-n-flip1
Elapsed time: 1.072000 seconds for rip-n-flip2
Elapsed time: 2.554000 seconds for LE
Elapsed time: 2.223000 seconds for MP

Command:
Command: test

Elapsed time: 1.051000 seconds for rip-n-flip1
Elapsed time: 1.072000 seconds for rip-n-flip2
Elapsed time: 2.543000 seconds for LE
Elapsed time: 2.233000 seconds for MP

Command:
Command: test

Elapsed time: 1.052000 seconds for rip-n-flip1
Elapsed time: 1.071000 seconds for rip-n-flip2
Elapsed time: 2.544000 seconds for LE
Elapsed time: 2.253000 seconds for MP

Command:
Command: test

Elapsed time: 1.052000 seconds for rip-n-flip1
Elapsed time: 1.181000 seconds for rip-n-flip2
Elapsed time: 2.563000 seconds for LE
Elapsed time: 2.264000 seconds for MP

Command:
Command: test

Elapsed time: 1.072000 seconds for rip-n-flip1
Elapsed time: 1.091000 seconds for rip-n-flip2
Elapsed time: 2.564000 seconds for LE
Elapsed time: 2.254000 seconds for MP
Code: [Select]
;;=============================================================
(defun c:test ()
  (setq lst1 '(1 11 3 6 7))
  (setq lst2 '(5 21 18 7 11 45))

  (startTimer)
  (repeat 10000
    (rip-n-flip1 lst1 lst2)
  )
  (endTimer "rip-n-flip1")
  (startTimer)
  (repeat 10000
    (rip-n-flip2 lst1 lst2)
  )
  (endTimer "rip-n-flip2")
  (startTimer)
  (repeat 10000
    (LE lst1 lst2)
  )
  (endTimer "LE")
  (startTimer)
  (repeat 10000
    (MP lst1 lst2)
  )
  (endTimer "MP")
  (princ)
)

(defun rip-n-flip2 (lm lc / l-m)
  (setq l-m (mapcar 'list lm))
  (foreach item lc
    (setq l-m (subst nil (list item) l-m))
  )
  (apply 'append l-m)
)
(defun rip-n-flip1 (lm lc / l-m cntr)
  (setq cntr (length lc)
        l-m  (mapcar 'list lm)
  )
  (while (> (setq cntr (1- cntr)) -1)
    (setq l-m (subst nil (list (nth cntr lc)) l-m))
  )
  (apply 'append l-m)
)


(defun LE (lst1 lst2 / i pos)
  (vl-some '(lambda (i / pos)
              (if (setq pos (vl-position i lst1))
                (list pos i)
              )
            )
           lst2
  )
)

(defun MP (lst1 lst2 / i pos)
  (vl-some
    '(lambda (item) (and (member item list2)))
    list1
  )
)


Code: [Select]
;;=============================================================
(defun startTimer ()
(setq time (getvar "MILLISECS"))
)
;;=============================================================
(defun endTimer (func)
 (setq time (/ (- (getvar "MILLISECS") time) 1000.0))
 (princ (strcat "\nElapsed time: " (rtos time 2 6) " seconds for " func))
  (gc)
)
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.

daron

  • Guest
list comparison
« Reply #36 on: July 11, 2005, 03:32:40 PM »
Wow. It's amazing. RNF1 and 2 are quite negligable, which would imply that the placement of the variables or use of them is also negligable. I would think it would take a sizable piece of code to really determine the effects of having variables vs. not having them. What's up with the VL commands? It seems that any time we've tested these things they always take longer.

LE

  • Guest
list comparison
« Reply #37 on: July 11, 2005, 04:51:34 PM »
Now I am totally confused... rewinding myself....

What is the desired results needed?

Code: [Select]

(setq l1 '(1 11 3 6 7))
(setq l2 '(5 21 18 7 11 45))

(7 11) <== this?


I did the test for (rip-n-flip1 lst1 lst2) and (rip-n-flip2 lst1 lst2) and it is returning:

Code: [Select]

(1 3 6) <== or this?


Or just need to know if one item from one list is in the other one, and get a boolean result?

Here are some other functions, not using vlisp:

Code: [Select]

(defun is_member  (l1 l2 / term lth i)
  (setq lth (length l1)
i   0)
  (while (and (< i lth) (not term))
    (if (member (nth i l1) l2)
      (setq term T))
    (setq i (1+ i)))
  term)

(defun members  (l1 l2 / lth i r)
  (setq lth (length l1)
i   0)
  (while (< i lth)
    (if (member (nth i l1) l2)
      (setq r (cons (nth i l1) r)))
    (setq i (1+ i)))
  (reverse r))

daron

  • Guest
list comparison
« Reply #38 on: July 11, 2005, 11:26:58 PM »
I'm sorry Luis. I didn't mean to confuse. The first issue I was having has been resolved. Since se7en (John) posted his Rip-n-Flip programs in here, I decided to keep them in here. The original function was for the purpose of determining whether or not a list item was the same in two different lists and return a boolean value. Today's purpose, I had two selection sets. One would have a certain amount of ss's in a list and the other would have many more items selected by their layer. This would inadvertently collect entities that were also in the first list. I wanted to remove the item from the second list that were in the first list and found John's RNF procedures to be quite successful. I modified it to suit and decided to post my findings and what I learned about it here. Actually, if anyone is confused, it is I.

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
list comparison
« Reply #39 on: July 12, 2005, 10:16:24 AM »
*blink blink* Am I reading that test right? I cant be reading that right! (My proced was faster then LE and MP?!)

Here would be my take on the slower vl issue.

Seeing as the Autolisp intrip. is "built in" to AutoCAD that is gonna be alot faster then requiring the app to refer to the DLL which is VL.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
list comparison
« Reply #40 on: July 12, 2005, 10:28:38 AM »
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.

daron

  • Guest
list comparison
« Reply #41 on: July 12, 2005, 01:05:31 PM »
Doesn't that just make you feel so good John?

JohnK

  • Administrator
  • Seagull
  • Posts: 10646
list comparison
« Reply #42 on: July 12, 2005, 03:39:57 PM »
Ummm, YES?!
<billy-madison-voice>
I am the smartest man alive!
</billy-madison-voice>

(Im finaly on the "correct" side of a discussion. ...w00t!)

*lol*
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org