Author Topic: -={ Challenge }=- SubStr for Lists  (Read 11656 times)

0 Members and 1 Guest are viewing this topic.

JohnK

  • Administrator
  • Seagull
  • Posts: 10638
Re: -={ Challenge }=- SubStr for Lists
« Reply #15 on: October 01, 2010, 05:38:49 PM »
*lmao* I didn't expect to be the fastest but i also didn't expect to be that far down the list either.
TheSwamp.org (serving the CAD community since 2003)
Member location map - Add yourself

Donate to TheSwamp.org

T.Willey

  • Needs a day job
  • Posts: 5251
Re: -={ Challenge }=- SubStr for Lists
« Reply #16 on: October 01, 2010, 05:39:48 PM »
Wow.  Didn't think it would be that much slower, my second version.  Thanks for the testing Kerry.

I wanted to remove one of the ' reverse ' calls, so here is another version.  :-D

Code: [Select]
(defun TW:SubList3 ( lst st len / tempList )
   
    (repeat st
        (setq lst (cdr lst))
    )
    (if
        (or
            (not lst)
            (not len)
            (zerop len)
        )
        lst
        (progn
            (repeat len
                (setq tempList (cons (car lst) tempList))
                (setq lst (cdr lst))
            )
            (reverse tempList)
        )
    )
)
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- SubStr for Lists
« Reply #17 on: October 01, 2010, 05:47:44 PM »

I wanted to remove one of the ' reverse ' calls, so here is another version.  :-D

Code: [Select]
(defun TW:SubList3 ( lst st len / tempList )
  ..<snip> 
 

About 25% Tim .. same as LM:SUBLIST-ITER
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.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: -={ Challenge }=- SubStr for Lists
« Reply #18 on: October 01, 2010, 05:56:38 PM »
ok, smth different and slow :)
Code: [Select]
(defun vk_GetSubList51 (lst s l / i)
  (repeat 2
    (setq i   0
  lst (reverse (vl-member-if (function (lambda (e) (< s (setq i (1+ i))))) lst))
  s   (- (length lst) l)
    )
  )
  lst
)

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- SubStr for Lists
« Reply #19 on: October 01, 2010, 06:01:49 PM »
Just dissected your func Kerry - nice method my friend  :wink:

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- SubStr for Lists
« Reply #20 on: October 01, 2010, 06:03:46 PM »
ok, smth different and slow :)

I like it!  :-)

T.Willey

  • Needs a day job
  • Posts: 5251
Re: -={ Challenge }=- SubStr for Lists
« Reply #21 on: October 01, 2010, 06:05:47 PM »

I wanted to remove one of the ' reverse ' calls, so here is another version.  :-D

Code: [Select]
(defun TW:SubList3 ( lst st len / tempList )
  ..<snip> 
 

About 25% Tim .. same as LM:SUBLIST-ITER

Hmmmm....... that is different than what I thought would happen.  Thanks again Kerry for running it.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- SubStr for Lists
« Reply #22 on: October 01, 2010, 06:16:54 PM »
Another perhaps:

Code: [Select]
(defun LM:SubList3 ( l s n / _left _right )

  (defun _left ( l s n )
    (if (and l (< 0 s))
      (_left (cdr l) (1- s) n)
      (_right (reverse l) s (cond (n (- (length l) n)) ( 0 )))
    )
  )

  (defun _right ( l s n )
    (if (and l (< 0 n))
      (_right (cdr l) s (1- n))
      (reverse l)
    )
  )

  (_left l s n)
)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- SubStr for Lists
« Reply #23 on: October 01, 2010, 06:23:06 PM »




Benchmarking [M.P. 2005 < revised kdub 2005>] ..................
Elapsed milliseconds for 32768 iteration(s)/ relative Timing :

    (TW:L-SUBLIST TESTLIST 9 13)........2871 / 2.4538 <slowest>
    (J7:SUBLIST TESTLIST 9 13)..........2028 / 1.7333
    (EE:F TESTLIST 9 13)................1779 / 1.5205
    (GILE:SUBLST TESTLIST 9 13).........1716 / 1.4667
    (LM:SUBLIST TESTLIST 9 13)..........1638 / 1.4000
    (LM:SUBLIST-ITER TESTLIST 9 13).....1498 / 1.2803
    (TW:SUBLIST3 TESTLIST 9 13).........1498 / 1.2803
    (VK_GETSUBLIST51 TESTLIST 9 13).....1482 / 1.2667
    (EE:F1 TESTLIST 9 13)...............1451 / 1.2402
    (LM:SUBLIST3 TESTLIST 9 13).........1450 / 1.2393
    (EE:F2 TESTLIST 9 13)...............1342 / 1.1470
    (AT:SUBLIST TESTLIST 9 13)..........1342 / 1.1470
    (GILE:SUBLIST TESTLIST 9 13)........1341 / 1.1462
    (TW:SUBLIST TESTLIST 9 13)..........1310 / 1.1197
    (KDUB:SUBLIST TESTLIST 9 13)........1170 / 1.0000 <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.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: -={ Challenge }=- SubStr for Lists
« Reply #24 on: October 01, 2010, 06:28:26 PM »
Thanks Kerry, I didn't think it would be too near the top with those recursive calls...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- SubStr for Lists
« Reply #25 on: October 01, 2010, 08:00:35 PM »
Just dissected your func Kerry - nice method my friend  :wink:

I have a feeling that the routine originated from gile.
I try to credit code but that particular function doesn't have an accreditation ...
If anyone recognises it, please stand up :-D
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: -={ Challenge }=- SubStr for Lists
« Reply #26 on: October 02, 2010, 12:39:09 AM »
Thanks Kerry, as the change results in long lists?
Code: [Select]
(setq i 0)
(repeat 10000
 (setq l (cons i l)
       i (1+ i)
 )
)
(test l 4000 8000)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: -={ Challenge }=- SubStr for Lists
« Reply #27 on: October 02, 2010, 04:57:13 AM »

Ahhhh That's another story :-)


(setq i 0
      TestList '()
)
(repeat 10000
  (setq TestList (cons i TestList)
        i        (1+ i)
  )
)


Benchmarking [M.P. 2005] ........Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (GILE:SUBLIST TESTLIST 4000 4000)........6599 / 70.2021 <slowest>
    (KDUB:SUBLIST TESTLIST 4000 4000)........4633 / 49.2872
    (J7:SUBLIST TESTLIST 4000 4000)..........1248 / 13.2766
    (EE:F TESTLIST 4000 4000).................312 / 3.3191
    (GILE:SUBLST TESTLIST 4000 4000)..........312 / 3.3191
    (TW:L-SUBLIST TESTLIST 4000 4000).........297 / 3.1596
    (LM:SUBLIST TESTLIST 4000 4000)...........266 / 2.8298
    (LM:SUBLIST3 TESTLIST 4000 4000)..........202 / 2.1489
    (LM:SUBLIST-ITER TESTLIST 4000 4000)......187 / 1.9894
    (TW:SUBLIST3 TESTLIST 4000 4000)..........187 / 1.9894
    (EE:F1 TESTLIST 4000 4000)................156 / 1.6596
    (AT:SUBLIST TESTLIST 4000 4000)...........156 / 1.6596
    (TW:SUBLIST TESTLIST 4000 4000)...........140 / 1.4894
    (VK_GETSUBLIST51 TESTLIST 4000 4000)......125 / 1.3298
    (EE:F2 TESTLIST 4000 4000).................94 / 1.0000 <fastest>


Benchmarking [M.P. 2005] ........Elapsed milliseconds for 32 iteration(s)/ relative Timing :

    (GILE:SUBLIST TESTLIST 20 9980)........13478 / 123.6514 <slowest>
    (KDUB:SUBLIST TESTLIST 20 9980).........9890 / 90.7339
    (J7:SUBLIST TESTLIST 20 9980)...........5928 / 54.3853
    (EE:F TESTLIST 20 9980)..................515 / 4.7248
    (LM:SUBLIST TESTLIST 20 9980)............437 / 4.0092
    (TW:L-SUBLIST TESTLIST 20 9980)..........437 / 4.0092
    (GILE:SUBLST TESTLIST 20 9980)...........436 / 4.0000
    (LM:SUBLIST-ITER TESTLIST 20 9980).......374 / 3.4312
    (TW:SUBLIST3 TESTLIST 20 9980)...........343 / 3.1468
    (EE:F2 TESTLIST 20 9980).................218 / 2.0000
    (EE:F1 TESTLIST 20 9980).................202 / 1.8532
    (VK_GETSUBLIST51 TESTLIST 20 9980).......109 / 1.0000
    (LM:SUBLIST3 TESTLIST 20 9980)...........109 / 1.0000
    (AT:SUBLIST TESTLIST 20 9980)............109 / 1.0000
    (TW:SUBLIST TESTLIST 20 9980)............109 / 1.0000 <fastest>

 
« Last Edit: October 02, 2010, 05:24:35 AM by Kerry »
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.

VovKa

  • Water Moccasin
  • Posts: 1631
  • Ukraine
Re: -={ Challenge }=- SubStr for Lists
« Reply #28 on: October 02, 2010, 06:33:17 AM »
now i must edit my post and remove the "slow" adjective :)

David Bethel

  • Swamp Rat
  • Posts: 656
Re: -={ Challenge }=- SubStr for Lists
« Reply #29 on: October 02, 2010, 07:31:20 AM »
Something simple ( like me )
Code: [Select]
(defun db:subl (l s e / i tmp)
  (setq i (1- s))
  (or e (setq e (length l)))
  (while (and (nth i l)
              (< i (+ s e -1)))
         (setq tmp (cons (nth i l) tmp)
                 i (1+ i)))
  (reverse tmp))
-David
R12 Dos - A2K