Author Topic: Replace nth member of a list  (Read 27582 times)

0 Members and 1 Guest are viewing this topic.

Keith™

  • Villiage Idiot
  • Seagull
  • Posts: 16899
  • Superior Stupidity at its best
Re: Replace nth member of a list
« Reply #30 on: December 28, 2006, 02:51:11 PM »
You guys are the greatest. This is a fun thread.
The checks in the mail. (ha!)
You should come and visit more often .. there are lots of other threads very similar to this one.

Oh .. and lest I forget .. the ideas posted here helped me resolve my problem and with a minor tweak to the combined code of CAB and Evgeniy I now have a working model that I can build upon. I appreciate the help guys .. seems like every now and then I just get a brain fart and can't seem to see the forest for all of the trees in the way.
Proud provider of opinion and arrogance since November 22, 2003 at 09:35:31 am
CadJockey Militia Field Marshal

Find me on https://parler.com @kblackie

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #31 on: December 28, 2006, 07:04:39 PM »
You guys are the greatest. This is a fun thread.
The checks in the mail. (ha!)

My mail empty...  :(

terrycadd

  • Guest
Re: Replace nth member of a list
« Reply #32 on: December 30, 2006, 12:51:16 AM »
I know this is not a contest, however concerning the speed of functions we can all benefit by the contributions of other programmers. Here are the results of the functions using my included c:TestNths function that determines the speed of the functions relating to the original title of this thread.
Code: [Select]
Command: TestNths
swapnth: 21543086
replase: 21544061
nth-replace: 21544324
replace: 21544728
replase_2: 21544986
Finished: 21545784
Lowest number for results is the fastest:
swapnth = 975
replase = 263
nth-replace = 404
replace = 258
replase_2 = 798

Command: TestNths
swapnth: 21550007
replase: 21550971
nth-replace: 21551233
replace: 21551635
replase_2: 21551893
Finished: 21552689
Lowest number for results is the fastest:
swapnth = 964
replase = 262
nth-replace = 402
replace = 258
replase_2 = 796

Command: TestNths
swapnth: 21593135
replase: 21594107
nth-replace: 21594370
replace: 21594772
replase_2: 21595030
Finished: 21595830
Lowest number for results is the fastest:
swapnth = 972
replase = 263
nth-replace = 402
replace = 258
replase_2 = 800

Command: TestNths
swapnth: 22000948
replase: 22001915
nth-replace: 22002177
replace: 22002579
replase_2: 22002837
Finished: 22003632
Lowest number for results is the fastest:
swapnth = 967
replase = 262
nth-replace = 402
replace = 258
replase_2 = 795
I ran this test several times and it returned similar results.
The “replace” function by Danielm103 was slightly faster than the “replase” function by Evgeniy.
Code: [Select]
(defun c:TestNths (/ Cnt# t1 t2 t3 t4 t5 t6)
  (if (not *List@);Create a 1000 item global *List@
    (repeat 10
      (setq Cnt# 48);Start at (ascii "0") (chr 48)
      (repeat 100
        (setq *List@ (append *List@ (list (chr Cnt#))))
        (setq Cnt# (1+ Cnt#))
      );repeat
    );repeat
  );if
  (princ "\nswapnth: ")
  (princ (setq t1 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (swapnth *List@ 998 "NEW"))
  (princ "\nreplase: ")
  (princ (setq t2 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replase *List@ 998 "NEW"))
  (princ "\nnth-replace: ")
  (princ (setq t3 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (nth-replace 998 "NEW" *List@))
  (princ "\nreplace: ")
  (princ (setq t4 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replace *List@ 998 "NEW"))
  (princ "\nreplase_2: ")
  (princ (setq t5 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replase_2 *List@ 998 "NEW"))
  (princ "\nFinished: ")
  (princ (setq t6 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (princ "\nLowest number for results is the fastest:")
  (princ "\nswapnth = ")    (princ (- t2 t1))
  (princ "\nreplase = ")    (princ (- t3 t2))
  (princ "\nnth-replace = ")(princ (- t4 t3))
  (princ "\nreplace = ")    (princ (- t5 t4))
  (princ "\nreplase_2 = ")  (princ (- t6 t5))
  (princ)
);defun c:TestNths

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #33 on: December 30, 2006, 03:56:15 AM »
I have obtained similar data, without compilation...
Compare speed after compilation!
AutoCad 2004

Checked this code:
Code: [Select]
;; CAB 11/15/2006
;;  replace nth item in list
(defun swapnth (lst i1 itm / tmp nlst)
  (while (and (> i1 0)
              (< (length (setq nlst (cons (car lst) nlst))) i1))
    (setq lst (cdr lst))
    )
  (setq nlst (cons itm nlst)
        lst (cddr lst))
  (while (or (setq tmp (car lst)) lst)
    (setq nlst (cons tmp nlst)
          lst (cdr lst))
    )
  (reverse nlst)
)
(defun replase (lst i itm)
  ;;(replase '(0 1 2 3 4 5 6) 3 "A")
  ;; =>
  ;; '(0 1 2 "A" 4 5 6)
  (mapcar
    (function
      (lambda (x)
        (if (zerop i)
          (progn (setq i (1- i)) itm)
          (progn (setq i (1- i)) x)
        ) ;_ if
      ) ;_ lambda
    ) ;_ function
    lst
  ) ;_ mapcar
) ;_ defun
(defun replase_1 (lst i itm)
  ;;(replase_1 '(0 1 2 3 4 5 6) 3 "A")
  ;; =>
  ;; '(0 1 2 "A" 4 5 6)
  (if lst
    (if (> i 0)
      (cons (car lst) (replase_1 (cdr lst) (1- i) itm))
      (cons itm (cdr lst))
    ) ;_ if
  ) ;_ if
)
(defun nth-replace ( pos new-item lst )
  ;; Nth-Replacer
  ;;
  ;; This procedure will itterate thru an
  ;; entire list to replace the nth item
  ;; of that list.
  ;;
  ;; (nth-replace 2 3 '(1 2 4 4))
  ;; (1 2 3 4)
  ;;
  ;; By: John (Se7en) K
  ;;     12.27.06
  ;;
  (if (null lst)
    nil
    (cons
      (if (eq pos 0) new-item (car lst))
      (nth-replace (1- pos) new-item (cdr lst)))) )
(defun replace (lst i itm)
  (setq i (1+ i))
  (mapcar
    '(lambda (x)
      (if (zerop (setq i (1- i))) itm x)
    )
    lst
  )
)
(defun replase_2 (lst i itm / c)
  ;;(replase_2 '(0 1 2 3 4 5 6) 3 "A")
  ;; =>
  ;; '(0 1 2 "A" 4 5 6)
  (setq c -1)
  (mapcar
    (function cdr)
    ((lambda (l)
       (subst
         (cons 0 itm)
         (assoc i l)
         l
       ) ;_ subst
     ) ;_ lambda
      (mapcar (function (lambda (x) (cons (setq c (1+ c)) x))) lst)
    )
  ) ;_ mapcar
) ;_ defun
(defun c:TestNths (/ Cnt# t1 t2 t3 t4 t5 t6)
  (if (not *List@);Create a 1000 item global *List@
    (repeat 10
      (setq Cnt# 48);Start at (ascii "0") (chr 48)
      (repeat 100
        (setq *List@ (append *List@ (list (chr Cnt#))))
        (setq Cnt# (1+ Cnt#))
      );repeat
    );repeat
  );if
  (princ "\nswapnth: ")
  (princ (setq t1 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (swapnth *List@ 998 "NEW"))
  (princ "\nreplase: ")
  (princ (setq t2 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replase *List@ 998 "NEW"))
  (princ "\nnth-replace: ")
  (princ (setq t3 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (nth-replace 998 "NEW" *List@))
  (princ "\nreplace: ")
  (princ (setq t4 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replace *List@ 998 "NEW"))
  (princ "\nreplase_1: ")
  (princ (setq t5 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replase_1 *List@ 998 "NEW"))
  (princ "\nreplase_2: ")
  (princ (setq t6 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (repeat 1000 (replase_2 *List@ 998 "NEW"))
  (princ "\nFinished: ")
  (princ (setq t7 (atoi (substr (rtos (getvar "cdate") 2 8) 10))))(princ)
  (princ "\nLowest number for results is the fastest:")
  (princ "\nswapnth = ")    (princ (- t2 t1))
  (princ "\nreplase = ")    (princ (- t3 t2))
  (princ "\nnth-replace = ")(princ (- t4 t3))
  (princ "\nreplace = ")    (princ (- t5 t4))
  (princ "\nreplase_1 = ")  (princ (- t6 t5))
  (princ "\nreplase_2 = ")  (princ (- t7 t6))
  (princ)
);defun c:TestNths

Results after compilation:
Code: [Select]
Command:
Command: (LOAD "D:/replase.VLX") nil

Command: 'VLIDE
Command:
Command: TestNths
swapnth: 11341072
replase: 11341546
nth-replace: 11341621
replace: 11341769
replase_1: 11341891
replase_2: 11342038
Finished: 11342197
Lowest number for results is the fastest:
swapnth = 474
replase = 75
nth-replace = 148
replace = 122
replase_1 = 147
replase_2 = 159

Command:
Command: TestNths
swapnth: 11344692
replase: 11345168
nth-replace: 11345246
replace: 11345398
replase_1: 11345538
replase_2: 11345685
Finished: 11345851
Lowest number for results is the fastest:
swapnth = 476
replase = 78
nth-replace = 152
replace = 140
replase_1 = 147
replase_2 = 166

Command:
Command: TestNths
swapnth: 11350462
replase: 11350933
nth-replace: 11351009
replace: 11351155
replase_1: 11351276
replase_2: 11351423
Finished: 11351581
Lowest number for results is the fastest:
swapnth = 471
replase = 76
nth-replace = 146
replace = 121
replase_1 = 147
replase_2 = 158

Command:
Command: TestNths
swapnth: 11352441
replase: 11352913
nth-replace: 11352990
replace: 11353141
replase_1: 11353269
replase_2: 11353420
Finished: 11353582
Lowest number for results is the fastest:
swapnth = 472
replase = 77
nth-replace = 151
replace = 128
replase_1 = 151
replase_2 = 162

Command:
Command: TestNths
swapnth: 11354036
replase: 11354512
nth-replace: 11354588
replace: 11354739
replase_1: 11354871
replase_2: 11355021
Finished: 11355184
Lowest number for results is the fastest:
swapnth = 476
replase = 76
nth-replace = 151
replace = 132
replase_1 = 150
replase_2 = 163

Command:

Results without compilation:

Code: [Select]
Command:
Command: (LOAD "D:/replase.LSP") C:TESTNTHS

Command: TestNths

swapnth: 11533020
replase: 11533675
nth-replace: 11533829
replace: 11534141
replase_1: 11534278
replase_2: 11534565
Finished: 11534774
Lowest number for results is the fastest:
swapnth = 655
replase = 154
nth-replace = 312
replace = 137
replase_1 = 287
replase_2 = 209

Command:
Command: TestNths
swapnth: 11535754
replase: 11540417
nth-replace: 11540575
replace: 11540888
replase_1: 11541032
replase_2: 11541324
Finished: 11541538
Lowest number for results is the fastest:
swapnth = 4663
replase = 158
nth-replace = 313
replace = 144
replase_1 = 292
replase_2 = 214

Command:
Command: TestNths
swapnth: 11541771
replase: 11542436
nth-replace: 11542590
replace: 11542902
replase_1: 11543051
replase_2: 11543344
Finished: 11543559
Lowest number for results is the fastest:
swapnth = 665
replase = 154
nth-replace = 312
replace = 149
replase_1 = 293
replase_2 = 215

Command:
Command: TestNths
swapnth: 11543785
replase: 11544473
nth-replace: 11544641
replace: 11544969
replase_1: 11545104
replase_2: 11545421
Finished: 11545646
Lowest number for results is the fastest:
swapnth = 688
replase = 168
nth-replace = 328
replace = 135
replase_1 = 317
replase_2 = 225

Command:
Command: TestNths
swapnth: 11545831
replase: 11550502
nth-replace: 11550670
replace: 11550990
replase_1: 11551142
replase_2: 11551450
Finished: 11551669
Lowest number for results is the fastest:
swapnth = 4671
replase = 168
nth-replace = 320
replace = 152
replase_1 = 308
replase_2 = 219

Command:

PS. You use compilation?
 :-)

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Replace nth member of a list
« Reply #34 on: December 30, 2006, 04:06:43 AM »
Terry, Michael [ MP ] has published a Benchmark.lsp for comparing performance .

here you go : ...
http://www.theswamp.org/lilly_pond/mp/lisp/benchmark.txt?nossi=1
Code: [Select]
    ;;=================================================================
    ;;
    ;;  Example:
    ;;
    ;;      (BenchMark
    ;;         '(
    ;;              (1+ 1)
    ;;              (+ 1 1)
    ;;              (+ 1 1.0)
    ;;              (+ 1.0 1.0)
    ;;          )
    ;;      )
    ;;
    ;;=================================================================
    ;;
    ;;  Output:
    ;;
    ;;      Elapsed milliseconds / relative speed for 32768 iteration(s):
    ;;
    ;;          (1+ 1)..........1969 / 1.09 <fastest>
    ;;          (+ 1 1).........2078 / 1.03
    ;;          (+ 1 1.0).......2125 / 1.01
    ;;          (+ 1.0 1.0).....2140 / 1.00 <slowest>   
    ;;
    ;;=================================================================

;; .... >>>> etc

The version I use is modified so that the fastest has a 1 factor  and the slowest has a higher factor, related to the time
... so it looks like this :-
Code: [Select]
Benchmarking [M.P. @ theSwamp 2005] ..................
Elapsed milliseconds for 32768 iteration(s)/ relative Timing :

    (+ 1 1.0).......1735 / 1.0188 <slowest>
    (+ 1.0 1.0).....1735 / 1.0188
    (+ 1 1).........1719 / 1.0094
    (1+ 1)..........1703 / 1 <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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Replace nth member of a list
« Reply #35 on: December 30, 2006, 08:31:43 AM »
This is what I got using MP Benchmark
Code: [Select]
Command: test
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (REPLASE_1 (QUOTE (0 1 2 3 4 5 6)) 3...).....1973 / 1.15 <fastest>
    (SWAPNTH (QUOTE (0 1 2 3 4 5 6)) 3 "A")......2113 / 1.08
    (NTH-REPLACE 3 "a" (QUOTE (0 1 2 3 4...).....2193 / 1.04
    (REPLACE_CAB (QUOTE (0 1 2 3 4 5 6))...).....2193 / 1.04
    (REPLASE (QUOTE (0 1 2 3 4 5 6)) 3 "A")......2214 / 1.03
    (REPLACE_DA "a" 3 (QUOTE (0 1 2 3 4 ...).....2273 / 1.00 <slowest>

Command:
Command: test
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (REPLASE_1 (QUOTE (0 1 2 3 4 5 6)) 3...).....1983 / 1.15 <fastest>
    (SWAPNTH (QUOTE (0 1 2 3 4 5 6)) 3 "A")......2123 / 1.08
    (REPLACE_CAB (QUOTE (0 1 2 3 4 5 6))...).....2203 / 1.04
    (NTH-REPLACE 3 "a" (QUOTE (0 1 2 3 4...).....2204 / 1.04
    (REPLASE (QUOTE (0 1 2 3 4 5 6)) 3 "A")......2223 / 1.03
    (REPLACE_DA "a" 3 (QUOTE (0 1 2 3 4 ...).....2283 / 1.00 <slowest>

Command:
Command: test
Elapsed milliseconds / relative speed for 16384 iteration(s):

    (REPLASE_1 (QUOTE (0 1 2 3 4 5 6)) 3...).....2003 / 1.14 <fastest>
    (SWAPNTH (QUOTE (0 1 2 3 4 5 6)) 3 "A")......2123 / 1.08
    (NTH-REPLACE 3 "a" (QUOTE (0 1 2 3 4...).....2204 / 1.04
    (REPLACE_CAB (QUOTE (0 1 2 3 4 5 6))...).....2223 / 1.03
    (REPLASE (QUOTE (0 1 2 3 4 5 6)) 3 "A")......2233 / 1.02
    (REPLACE_DA "a" 3 (QUOTE (0 1 2 3 4 ...).....2283 / 1.00 <slowest>
   
Code: [Select]
(defun c:test ()
  (BenchMark
    '((replace_Da "a" 3 '(0 1 2 3 4 5 6))
      (nth-replace 3 "a" '(0 1 2 3 4 5 6))
      (swapnth '(0 1 2 3 4 5 6) 3 "A")
      (replase '(0 1 2 3 4 5 6) 3 "A")
      (replace_CAB '(0 1 2 3 4 5 6) 3 "A")
      (replase_1 '(0 1 2 3 4 5 6) 3 "A")
     )
  )
)



Code: [Select]
;;  Danielm103
;;(replace "a" 3 '(0 1 2 3 4 5 6))
(defun replace_Da (a n lst / e i nl)
 (setq nl '()
       i 0
 )
 (foreach e lst
  (if (= i n)
   (setq nl (cons a nl))
   (setq nl (cons e nl))
  )
  (setq i (1+ i))
 )
 (reverse nl)
)


;; CAB 11/15/2006
;;  replace nth item in list
(defun swapnth (lst i1 itm / tmp nlst)
  (while (and (> i1 0)
              (< (length (setq nlst (cons (car lst) nlst))) i1))
    (setq lst (cdr lst))
    )
  (setq nlst (cons itm nlst)
        lst (cddr lst))
  (while (or (setq tmp (car lst)) lst)
    (setq nlst (cons tmp nlst)
          lst (cdr lst))
    )
  (reverse nlst)
)


;;  Evigeny
(defun replase (lst i itm)
  ;;(replase '(0 1 2 3 4 5 6) 3 "A")
  ;; =>
  ;; '(0 1 2 "A" 4 5 6)
  (mapcar
    (function
      (lambda (x)
        (if (zerop i)
          (progn (setq i (1- i)) itm)
          (progn (setq i (1- i)) x)
        )
      )
    )
    lst
  )
)


;; variation by CAB
(defun replace_CAB (lst i itm)
  (setq i (1+ i))
  (mapcar '(lambda (x) (if (zerop (setq i (1- i))) itm x)) lst)
)


;;  Evigeny
(defun replase_1 (lst i itm)
  ;;(replase_1 '(0 1 2 3 4 5 6) 3 "A")
  ;; =>
  ;; '(0 1 2 "A" 4 5 6)
  (if lst
    (if (> i 0)
      (cons (car lst) (replase_1 (cdr lst) (1- i) itm))
      (cons itm (cdr lst))
    ) ;_ if
  ) ;_ if
)

(defun nth-replace ( pos new-item lst )
  ;; Nth-Replacer
  ;;
  ;; This procedure will itterate thru an
  ;; entire list to replace the nth item
  ;; of that list.
  ;;
  ;; (nth-replace 2 3 '(1 2 4 4))
  ;; (1 2 3 4)
  ;;
  ;; By: John (Se7en) K
  ;;     12.27.06
  ;;
  (if (null lst)
    nil
    (cons
      (if (eq pos 0) new-item (car lst))
      (nth-replace (1- pos) new-item (cdr lst)))) )
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.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Replace nth member of a list
« Reply #36 on: December 30, 2006, 08:55:13 AM »
Changing the test to this changed the results:
See Terry's code to create *List@
Code: [Select]
(defun c:test ()
  (BenchMark
    '((replace_Da "NEW" 998 *List@)
      (nth-replace 998 "NEW" *List@)
      (swapnth *List@ 998 "NEW")
      (replase *List@ 998 "NEW")
      (replace_CAB *List@ 998 "NEW")
      (replase_1 *List@ 998 "NEW")
     )
  )
)

Code: [Select]
Command: test
Elapsed milliseconds / relative speed for 512 iteration(s):

    (REPLACE_CAB *LIST@ 998 "NEW").....1011 / 3.90 <fastest>
    (REPLASE *LIST@ 998 "NEW").........1072 / 3.68
    (REPLASE_1 *LIST@ 998 "NEW").......1833 / 2.15
    (REPLACE_DA "NEW" 998 *LIST@)......1902 / 2.07
    (NTH-REPLACE 998 "NEW" *LIST@).....1952 / 2.02
    (SWAPNTH *LIST@ 998 "NEW").........3946 / 1.00 <slowest>

Command:
Command: test
Elapsed milliseconds / relative speed for 512 iteration(s):

    (REPLACE_CAB *LIST@ 998 "NEW").....1011 / 3.90 <fastest>
    (REPLASE *LIST@ 998 "NEW").........1072 / 3.68
    (REPLASE_1 *LIST@ 998 "NEW").......1833 / 2.15
    (REPLACE_DA "NEW" 998 *LIST@)......1923 / 2.05
    (NTH-REPLACE 998 "NEW" *LIST@).....2083 / 1.89
    (SWAPNTH *LIST@ 998 "NEW").........3946 / 1.00 <slowest>
   
   
And changing the test again to this:
Code: [Select]
(defun c:test ()
  (BenchMark
    '((replace_Da "NEW" 5 *List@)
      (nth-replace 998 "NEW" *List@)
      (swapnth *List@ 5 "NEW")
      (replase *List@ 5 "NEW")
      (replace_CAB *List@ 5 "NEW")
      (replase_1 *List@ 5 "NEW")
     )
  )
)
WOW - what do you suppose is going on here.. :)
Code: [Select]
Command: test
Elapsed milliseconds / relative speed for 8192 iteration(s):

    (REPLASE_1 *LIST@ 5 "NEW")........1011 / 30.91 <fastest>
    (REPLACE_CAB *LIST@ 5 "NEW").....16043 / 1.95
    (REPLASE *LIST@ 5 "NEW").........17195 / 1.82
    (SWAPNTH *LIST@ 5 "NEW").........22052 / 1.42
    (REPLACE_DA "NEW" 5 *LIST@)......30293 / 1.03
    (NTH-REPLACE 5 "NEW" *LIST@).....31245 / 1.00 <slowest>

Command:
Command: test
Elapsed milliseconds / relative speed for 8192 iteration(s):

    (REPLASE_1 *LIST@ 5 "NEW")........1021 / 30.65 <fastest>
    (REPLACE_CAB *LIST@ 5 "NEW").....16123 / 1.94
    (REPLASE *LIST@ 5 "NEW").........17335 / 1.81
    (SWAPNTH *LIST@ 5 "NEW").........22082 / 1.42
    (REPLACE_DA "NEW" 5 *LIST@)......30504 / 1.03
    (NTH-REPLACE 5 "NEW" *LIST@).....31295 / 1.00 <slowest>


<edit, added the second test routine...>
« Last Edit: December 30, 2006, 06:40:12 PM by CAB »
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.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8639
  • AKA Daniel
Re: Replace nth member of a list
« Reply #37 on: December 30, 2006, 12:02:07 PM »
Evigeny’s replase_1 Rocks!!!

Good job  Evigeny :-D

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #38 on: December 30, 2006, 01:10:14 PM »
>CAB
You used compilation in this testing?

« Last Edit: December 30, 2006, 06:19:07 PM by CAB »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Replace nth member of a list
« Reply #39 on: December 30, 2006, 06:18:47 PM »
No, sorry, I was too lazy. :oops:

Oh, I forgot to include the second test routine, see the post above, I added it.

In your recursive routine, it stops when the replacement is made so in that test
it stopped after 6 iterations.
« Last Edit: December 30, 2006, 06:42:29 PM by CAB »
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #40 on: December 31, 2006, 05:08:49 AM »
In your recursive routine, it stops when the replacement is made so in that test
it stopped after 6 iterations.

All works for me correctly...
Probably, I have not understood your question :(

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #41 on: December 31, 2006, 05:21:16 AM »
No, sorry, I was too lazy. :oops:

I have made it.  :)
Very interesting results have turned out!  :-)

It is the program of testing:
Code: [Select]
(defun c:test (/ *LIST@ CNT# I)
  (if (not *List@)
    (repeat 10
      (setq Cnt# 48)
      (repeat 100
        (setq *List@ (append *List@ (list (chr Cnt#))))
        (setq Cnt# (1+ Cnt#))
      ) ;repeat
    ) ;repeat
  ) ;_  if
  (setq i 99)
  (repeat 10
    (princ (strcat "\n\nI = " (itoa i) "\n"))
    (BenchMark
      '((replace_Da "A" i *List@)
        (nth-replace i "A" *List@)
        (swapnth *List@ i "A")
        (replase *List@ i "A")
        (replace_CAB *List@ i "A")
        (replase_1 *List@ i "A")
        (replase_2 *List@ i "A")
       )
    ) ;_  BenchMark
    (setq i (+ i 100))
  ) ;_  repeat
) ;_  defun

It is a code, for testing:
Code: [Select]
;;  test.lsp
(defun replace_Da (a n lst / e i nl)
  ;;  Danielm103
  (setq nl '()
        i  0
  ) ;_  setq
  (foreach e lst
    (if (= i n)
      (setq nl (cons a nl))
      (setq nl (cons e nl))
    ) ;_  if
    (setq i (1+ i))
  ) ;_  foreach
  (reverse nl)
) ;_  defun
(defun swapnth (lst i1 itm / tmp nlst)
;; CAB 11/15/2006
;;  replace nth item in list
  (while (and (> i1 0)
              (< (length (setq nlst (cons (car lst) nlst))) i1)
         ) ;_  and
    (setq lst (cdr lst))
  ) ;_  while
  (setq nlst (cons itm nlst)
        lst  (cddr lst)
  ) ;_  setq
  (while (or (setq tmp (car lst)) lst)
    (setq nlst (cons tmp nlst)
          lst  (cdr lst)
    ) ;_  setq
  ) ;_  while
  (reverse nlst)
) ;_  defun
(defun replase (lst i itm)
  ;; ElpanovEvgeniy
  (mapcar
    (function
      (lambda (x)
        (if (zerop i)
          (progn (setq i (1- i)) itm)
          (progn (setq i (1- i)) x)
        ) ;_  if
      ) ;_  lambda
    ) ;_  function
    lst
  ) ;_  mapcar
) ;_  defun
(defun replace_CAB (lst i itm)
;; variation by CAB
  (setq i (1+ i))
  (mapcar '(lambda (x)
             (if (zerop (setq i (1- i)))
               itm
               x
             ) ;_  if
           ) ;_  lambda
          lst
  ) ;_  mapcar
) ;_  defun
(defun replase_1 (lst i itm)
  ;; ElpanovEvgeniy
  (if lst
    (if (> i 0)
      (cons (car lst) (replase_1 (cdr lst) (1- i) itm))
      (cons itm (cdr lst))
    ) ;_ if
  ) ;_ if
) ;_  defun
(defun nth-replace (pos new-item lst)
  ;; By: John (Se7en) K 12.27.06
  (if (null lst)
    nil
    (cons
      (if (eq pos 0)
        new-item
        (car lst)
      ) ;_  if
      (nth-replace (1- pos) new-item (cdr lst))
    ) ;_  cons
  ) ;_  if
) ;_  defun
(defun replase_2 (lst i itm / c)
  ;; ElpanovEvgeniy
  (setq c -1)
  (mapcar
    (function cdr)
    ((lambda (l)
       (subst
         (cons 0 itm)
         (assoc i l)
         l
       ) ;_ subst
     ) ;_ lambda
      (mapcar (function (lambda (x) (cons (setq c (1+ c)) x))) lst)
    )
  ) ;_ mapcar
)

These are results without compilation:
Code: [Select]
Command:
Command: (LOAD "E:/test.LSP") C:TEST

Command: test


I = 99
Elapsed milliseconds / relative speed for 4096 iteration(s):

    (REPLASE_1 *LIST@ I "A")........1437 / 9.99 <fastest>
    (REPLACE_CAB *LIST@ I "A")......6625 / 2.17
    (REPLASE *LIST@ I "A")..........7187 / 2.00
    (REPLASE_2 *LIST@ I "A").......10265 / 1.40
    (SWAPNTH *LIST@ I "A").........10313 / 1.39
    (NTH-REPLACE I "A" *LIST@).....13812 / 1.04
    (REPLACE_DA "A" I *LIST@)......14359 / 1.00 <slowest>


I = 199
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1328 / 5.33 <fastest>
    (REPLACE_CAB *LIST@ I "A").....3234 / 2.19
    (REPLASE *LIST@ I "A").........3656 / 1.94
    (REPLASE_2 *LIST@ I "A").......5141 / 1.38
    (SWAPNTH *LIST@ I "A").........5766 / 1.23
    (NTH-REPLACE I "A" *LIST@).....6906 / 1.02
    (REPLACE_DA "A" I *LIST@)......7078 / 1.00 <slowest>


I = 299
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1016 / 3.41 <fastest>
    (REPLACE_CAB *LIST@ I "A").....1672 / 2.07
    (REPLASE *LIST@ I "A").........1828 / 1.90
    (REPLASE_2 *LIST@ I "A").......2531 / 1.37
    (SWAPNTH *LIST@ I "A").........3156 / 1.10
    (NTH-REPLACE I "A" *LIST@).....3391 / 1.02
    (REPLACE_DA "A" I *LIST@)......3469 / 1.00 <slowest>


I = 399
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1297 / 2.70 <fastest>
    (REPLACE_CAB *LIST@ I "A").....1672 / 2.09
    (REPLASE *LIST@ I "A").........1781 / 1.97
    (REPLASE_2 *LIST@ I "A").......2594 / 1.35
    (NTH-REPLACE I "A" *LIST@).....3484 / 1.00
    (REPLACE_DA "A" I *LIST@)......3500 / 1.00
    (SWAPNTH *LIST@ I "A").........3500 / 1.00 <slowest>


I = 499
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A").....1578 / 2.53 <fastest>
    (REPLASE_1 *LIST@ I "A").......1657 / 2.40
    (REPLASE *LIST@ I "A").........1813 / 2.20
    (REPLASE_2 *LIST@ I "A").......2610 / 1.53
    (NTH-REPLACE I "A" *LIST@).....3422 / 1.16
    (REPLACE_DA "A" I *LIST@)......3547 / 1.12
    (SWAPNTH *LIST@ I "A").........3985 / 1.00 <slowest>


I = 599
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A").....1671 / 2.58 <fastest>
    (REPLASE *LIST@ I "A").........1829 / 2.36
    (REPLASE_1 *LIST@ I "A").......1969 / 2.19
    (REPLASE_2 *LIST@ I "A").......2532 / 1.70
    (REPLACE_DA "A" I *LIST@)......3468 / 1.24
    (NTH-REPLACE I "A" *LIST@).....3516 / 1.23
    (SWAPNTH *LIST@ I "A").........4313 / 1.00 <slowest>


I = 699
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A").....1641 / 3.06 <fastest>
    (REPLASE *LIST@ I "A").........1828 / 2.74
    (REPLASE_1 *LIST@ I "A").......2281 / 2.20
    (REPLASE_2 *LIST@ I "A").......2563 / 1.96
    (NTH-REPLACE I "A" *LIST@).....3390 / 1.48
    (REPLACE_DA "A" I *LIST@)......3594 / 1.40
    (SWAPNTH *LIST@ I "A").........5016 / 1.00 <slowest>


I = 799
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A").....1593 / 3.58 <fastest>
    (REPLASE *LIST@ I "A").........1829 / 3.12
    (REPLASE_2 *LIST@ I "A").......2609 / 2.19
    (REPLASE_1 *LIST@ I "A").......2625 / 2.17
    (NTH-REPLACE I "A" *LIST@).....3375 / 1.69
    (REPLACE_DA "A" I *LIST@)......3609 / 1.58
    (SWAPNTH *LIST@ I "A").........5703 / 1.00 <slowest>


I = 899
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A").....1562 / 4.08 <fastest>
    (REPLASE *LIST@ I "A").........1828 / 3.49
    (REPLASE_2 *LIST@ I "A").......2610 / 2.44
    (REPLASE_1 *LIST@ I "A").......2938 / 2.17
    (REPLACE_DA "A" I *LIST@)......3328 / 1.92
    (NTH-REPLACE I "A" *LIST@).....3453 / 1.85
    (SWAPNTH *LIST@ I "A").........6375 / 1.00 <slowest>


I = 999
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A").....1421 / 5.00 <fastest>
    (REPLASE *LIST@ I "A").........1813 / 3.92
    (REPLASE_2 *LIST@ I "A").......2547 / 2.79
    (REPLASE_1 *LIST@ I "A").......3313 / 2.15
    (REPLACE_DA "A" I *LIST@)......3454 / 2.06
    (NTH-REPLACE I "A" *LIST@).....3516 / 2.02
    (SWAPNTH *LIST@ I "A").........7110 / 1.00 <slowest>
1099

Command:

These are results after compilation:
Code: [Select]
Command:
Command: (LOAD "E:/test.VLX") nil

Command: test


I = 99
Elapsed milliseconds / relative speed for 8192 iteration(s):

    (REPLASE_1 *LIST@ I "A")........1719 / 8.83 <fastest>
    (REPLASE *LIST@ I "A")..........7094 / 2.14
    (SWAPNTH *LIST@ I "A")..........8985 / 1.69
    (REPLACE_DA "A" I *LIST@).......9375 / 1.62
    (REPLACE_CAB *LIST@ I "A").....10156 / 1.49
    (NTH-REPLACE I "A" *LIST@).....13047 / 1.16
    (REPLASE_2 *LIST@ I "A").......15172 / 1.00 <slowest>


I = 199
Elapsed milliseconds / relative speed for 4096 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1500 / 5.11 <fastest>
    (REPLASE *LIST@ I "A").........3547 / 2.16
    (REPLACE_DA "A" I *LIST@)......4688 / 1.64
    (REPLACE_CAB *LIST@ I "A").....5110 / 1.50
    (SWAPNTH *LIST@ I "A").........5187 / 1.48
    (NTH-REPLACE I "A" *LIST@).....6500 / 1.18
    (REPLASE_2 *LIST@ I "A").......7672 / 1.00 <slowest>


I = 299
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1046 / 3.65 <fastest>
    (REPLASE *LIST@ I "A").........1766 / 2.16
    (REPLACE_DA "A" I *LIST@)......2375 / 1.61
    (REPLACE_CAB *LIST@ I "A").....2516 / 1.52
    (SWAPNTH *LIST@ I "A").........3062 / 1.25
    (NTH-REPLACE I "A" *LIST@).....3250 / 1.17
    (REPLASE_2 *LIST@ I "A").......3813 / 1.00 <slowest>


I = 399
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1360 / 2.80 <fastest>
    (REPLASE *LIST@ I "A").........1781 / 2.14
    (REPLACE_DA "A" I *LIST@)......2360 / 1.62
    (REPLACE_CAB *LIST@ I "A").....2547 / 1.50
    (NTH-REPLACE I "A" *LIST@).....3250 / 1.17
    (SWAPNTH *LIST@ I "A").........3672 / 1.04
    (REPLASE_2 *LIST@ I "A").......3813 / 1.00 <slowest>


I = 499
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE_1 *LIST@ I "A").......1688 / 2.60 <fastest>
    (REPLASE *LIST@ I "A").........1782 / 2.46
    (REPLACE_DA "A" I *LIST@)......2328 / 1.89
    (REPLACE_CAB *LIST@ I "A").....2547 / 1.72
    (NTH-REPLACE I "A" *LIST@).....3265 / 1.34
    (REPLASE_2 *LIST@ I "A").......3828 / 1.15
    (SWAPNTH *LIST@ I "A").........4390 / 1.00 <slowest>


I = 599
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE *LIST@ I "A").........1765 / 2.97 <fastest>
    (REPLASE_1 *LIST@ I "A").......2000 / 2.62
    (REPLACE_DA "A" I *LIST@)......2344 / 2.23
    (REPLACE_CAB *LIST@ I "A").....2563 / 2.04
    (NTH-REPLACE I "A" *LIST@).....3265 / 1.60
    (REPLASE_2 *LIST@ I "A").......3828 / 1.37
    (SWAPNTH *LIST@ I "A").........5234 / 1.00 <slowest>


I = 699
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE *LIST@ I "A").........1766 / 3.53 <fastest>
    (REPLASE_1 *LIST@ I "A").......2297 / 2.71
    (REPLACE_DA "A" I *LIST@)......2344 / 2.66
    (REPLACE_CAB *LIST@ I "A").....2547 / 2.45
    (NTH-REPLACE I "A" *LIST@).....3266 / 1.91
    (REPLASE_2 *LIST@ I "A").......3828 / 1.63
    (SWAPNTH *LIST@ I "A").........6235 / 1.00 <slowest>


I = 799
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE *LIST@ I "A").........1781 / 4.13 <fastest>
    (REPLACE_DA "A" I *LIST@)......2344 / 3.14
    (REPLACE_CAB *LIST@ I "A").....2563 / 2.87
    (REPLASE_1 *LIST@ I "A").......2625 / 2.80
    (NTH-REPLACE I "A" *LIST@).....3250 / 2.26
    (REPLASE_2 *LIST@ I "A").......3859 / 1.91
    (SWAPNTH *LIST@ I "A").........7359 / 1.00 <slowest>


I = 899
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE *LIST@ I "A").........1766 / 4.88 <fastest>
    (REPLACE_DA "A" I *LIST@)......2344 / 3.67
    (REPLACE_CAB *LIST@ I "A").....2547 / 3.38
    (REPLASE_1 *LIST@ I "A").......2922 / 2.95
    (NTH-REPLACE I "A" *LIST@).....3265 / 2.64
    (REPLASE_2 *LIST@ I "A").......3844 / 2.24
    (SWAPNTH *LIST@ I "A").........8610 / 1.00 <slowest>


I = 999
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLASE *LIST@ I "A").........1781 / 5.61 <fastest>
    (REPLACE_DA "A" I *LIST@)......2343 / 4.26
    (REPLACE_CAB *LIST@ I "A").....2578 / 3.87
    (REPLASE_1 *LIST@ I "A").......3235 / 3.09
    (NTH-REPLACE I "A" *LIST@).....3250 / 3.07
    (REPLASE_2 *LIST@ I "A").......3860 / 2.59
    (SWAPNTH *LIST@ I "A").........9984 / 1.00 <slowest>
1099

Command:

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Replace nth member of a list
« Reply #42 on: December 31, 2006, 08:09:33 AM »
Thanks Evgeniy,
You can now see how the position of the index in the list affects the time required.
Also the compiling surprised me as I thought it would be a uniform change in the speed & not the order.
Funny how some methods fair better when compiled.
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.

ElpanovEvgeniy

  • Water Moccasin
  • Posts: 1569
  • Moscow (Russia)
Re: Replace nth member of a list
« Reply #43 on: December 31, 2006, 09:09:17 AM »
Thanks Evgeniy,
You can now see how the position of the index in the list affects the time required.
Also the compiling surprised me as I thought it would be a uniform change in the speed & not the order.
Funny how some methods fair better when compiled.

I wish to give you a small gift by new year...  :-)  :-)  :-)

Code: [Select]
(defun replace_CAB (lst i itm)
  ;; variation by CAB
  (setq i (1+ i))
  (mapcar '(lambda (x)
             (if (zerop (setq i (1- i)))
               itm
               x
             ) ;_  if
           ) ;_  lambda
          lst
  ) ;_  mapcar
) ;_  defun
(defun replace_CAB_optim (lst i itm)
  ;; variation by CAB
  (setq i (1+ i))
  (mapcar
    (function
      (lambda (x)
        (if (zerop (setq i (1- i)))
          itm
          x
        ) ;_  if
      ) ;_  lambda
    ) ;_  function
    lst
  ) ;_  mapcar
) ;_  defun

(defun c:test (/ *LIST@ CNT# I)
  (if (not *List@)
    (repeat 10
      (setq Cnt# 48)
      (repeat 100
        (setq *List@ (append *List@ (list (chr Cnt#))))
        (setq Cnt# (1+ Cnt#))
      ) ;repeat
    ) ;repeat
  ) ;_  if
  (setq i 99)
  (repeat 10
    (princ (strcat "\n\nI = " (itoa i) "\n"))
    (BenchMark
      '((replace_CAB *List@ i "A")
        (replace_CAB_optim *List@ i "A")
       )
    ) ;_  BenchMark
    (setq i (+ i 100))
  ) ;_  repeat
) ;_  defun

not compiled

Code: [Select]
Command: (LOAD "E:/test_1.LSP") C:TEST

Command: test


I = 99
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1453 / 1.03 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1500 / 1.00 <slowest>


I = 199
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1407 / 1.07 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1500 / 1.00 <slowest>


I = 299
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1422 / 1.02 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1454 / 1.00 <slowest>


I = 399
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1406 / 1.04 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1469 / 1.00 <slowest>


I = 499
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1422 / 1.03 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1469 / 1.00 <slowest>


I = 599
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1422 / 1.03 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1469 / 1.00 <slowest>


I = 699
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1407 / 1.06 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1485 / 1.00 <slowest>


I = 799
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1406 / 1.06 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1484 / 1.00 <slowest>


I = 899
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1422 / 1.04 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1485 / 1.00 <slowest>


I = 999
Elapsed milliseconds / relative speed for 1024 iteration(s):

    (REPLACE_CAB *LIST@ I "A")...........1422 / 1.02 <fastest>
    (REPLACE_CAB_OPTIM *LIST@ I "A").....1453 / 1.00 <slowest>
1099

Command:

after compiled

Code: [Select]
Command:
Command: (LOAD "E:/test_1.VLX") nil

Command: test


I = 99
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1719 / 1.47 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2531 / 1.00 <slowest>


I = 199
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1734 / 1.48 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2563 / 1.00 <slowest>


I = 299
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1672 / 1.51 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2531 / 1.00 <slowest>


I = 399
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1671 / 1.48 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2469 / 1.00 <slowest>


I = 499
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1671 / 1.52 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2532 / 1.00 <slowest>


I = 599
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1687 / 1.46 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2469 / 1.00 <slowest>


I = 699
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1672 / 1.52 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2546 / 1.00 <slowest>


I = 799
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1703 / 1.45 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2469 / 1.00 <slowest>


I = 899
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1688 / 1.49 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2516 / 1.00 <slowest>


I = 999
Elapsed milliseconds / relative speed for 2048 iteration(s):

    (REPLACE_CAB_OPTIM *LIST@ I "A").....1671 / 1.50 <fastest>
    (REPLACE_CAB *LIST@ I "A")...........2500 / 1.00 <slowest>
1099

Command:

 :-)
I congratulate on coming new year!
Let new year will bring a lot of pleasure and happiness!
Happy New Year!
 :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Replace nth member of a list
« Reply #44 on: December 31, 2006, 01:21:25 PM »
Thank you Sir. :)
And may you experience the same.

So, FUNCTION pays speed dividends. 8-)
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.