Author Topic: vl-position vs member  (Read 8811 times)

0 Members and 1 Guest are viewing this topic.

Marc'Antonio Alessi

  • Swamp Rat
  • Posts: 1451
  • Marco
Re: vl-position vs member
« Reply #15 on: May 02, 2015, 03:57:49 PM »
... instead of writing all those functions by hand, using lots of copy-paste and manual edits (i.e. a great many chances of making mistakes) you use stuff like eval to write code which "writes" code  :o . Of course it's not (yet) as powerful as those defmacro ideas in Common Lisp / Scheme, but it's "getting close"  ;)
Ok, this is similar to what has been done in this thread:
http://www.theswamp.org/index.php?topic=45900.msg511029#msg511029      :)


irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: vl-position vs member
« Reply #16 on: May 04, 2015, 03:07:12 AM »
... instead of writing all those functions by hand, using lots of copy-paste and manual edits (i.e. a great many chances of making mistakes) you use stuff like eval to write code which "writes" code  :o . Of course it's not (yet) as powerful as those defmacro ideas in Common Lisp / Scheme, but it's "getting close"  ;)
Ok, this is similar to what has been done in this thread:
http://www.theswamp.org/index.php?topic=45900.msg511029#msg511029      :)
+1  ;D
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: vl-position vs member
« Reply #17 on: May 04, 2015, 03:32:13 AM »
My point is I used the vl-position trick to get index in list.
Main use is to make sure a point is there or not.
In that case, vl-position (on its own) would always be the fastest on average ... for that particular situation.


Anyhow, seeing as all you want is to test if an item is inside a list, the car's are also unnecessary, as is that nthcdr. The other method of finding a value inside a list (i.e. using vl-some) is even worse than member:
Code - Auto/Visual Lisp: [Select]
  1. ;; Setup test list
  2. (progn (setq Test '() n 0)
  3.   (repeat 10000 (setq Test (cons (setq n (1+ n)) Test)))
  4.   (length Test))
  5.  
  6.  
  7. (defun IsInList (item L)
  8.   (vl-some (function (lambda (a) (equal a item))) L))


And my tests for this (1000th item, 5000th item and 9000th item):
Code: [Select]
_$ (QBench '((vl-position 9000 Test) (member 9000 Test) (IsInList 9000 Test) (vl-position 1000 Test) (member 1000 Test) (IsInList 1000 Test) (vl-position 5000 Test) (member 5000 Test) (IsInList 5000 Test)))
Benchmarking ......... done for 32768 iterations. Sorted from fastest.
Statement                                Increment  Time(ms) Normalize  Relative
--------------------------------------------------------------------------------
(VL-POSITION 9000 TEST)                      32768      1763      1763      1.00
(VL-POSITION 5000 TEST)                      16384      1420      2840      1.61
(VL-POSITION 1000 TEST)                      16384      1887      3774      2.14
(MEMBER 9000 TEST)                            8192      1779      7116      4.04
(ISINLIST 9000 TEST)                          2048      1497     23952     13.59
(MEMBER 5000 TEST)                            2048      1857     29712     16.85
(MEMBER 1000 TEST)                            1024      1623     51936     29.46
(ISINLIST 5000 TEST)                           512      1747    111808     63.42
(ISINLIST 1000 TEST)                           256      1544    197632    112.10
--------------------------------------------------------------------------------
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.

ymg

  • Guest
Re: vl-position vs member
« Reply #18 on: May 04, 2015, 05:23:46 PM »
Irneb,

For that particular situation vl-position is always faster.

On list of a couple of hundred items, difference is marginal.

As the list grows, it becomes very perceptible.

Thanks,

ymg

irneb

  • Water Moccasin
  • Posts: 1794
  • ACad R9-2016, Revit Arch 6-2016
Re: vl-position vs member
« Reply #19 on: May 05, 2015, 02:07:19 AM »
For that particular situation vl-position is always faster.

On list of a couple of hundred items, difference is marginal.

As the list grows, it becomes very perceptible.
Agreed
In that case, vl-position (on its own) would always be the fastest on average ... for that particular situation.
Common sense - the curse in disguise. Because if you have it, you have to live with those that don't.