0 Members and 1 Guest are viewing this topic.
You guys are the greatest. This is a fun thread.The checks in the mail. (ha!)
Command: TestNthsswapnth: 21543086replase: 21544061nth-replace: 21544324replace: 21544728replase_2: 21544986Finished: 21545784Lowest number for results is the fastest:swapnth = 975replase = 263nth-replace = 404replace = 258replase_2 = 798Command: TestNthsswapnth: 21550007replase: 21550971nth-replace: 21551233replace: 21551635replase_2: 21551893Finished: 21552689Lowest number for results is the fastest:swapnth = 964replase = 262nth-replace = 402replace = 258replase_2 = 796Command: TestNthsswapnth: 21593135replase: 21594107nth-replace: 21594370replace: 21594772replase_2: 21595030Finished: 21595830Lowest number for results is the fastest:swapnth = 972replase = 263nth-replace = 402replace = 258replase_2 = 800Command: TestNthsswapnth: 22000948replase: 22001915nth-replace: 22002177replace: 22002579replase_2: 22002837Finished: 22003632Lowest number for results is the fastest:swapnth = 967replase = 262nth-replace = 402replace = 258replase_2 = 795
(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
;; 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
Command:Command: (LOAD "D:/replase.VLX") nilCommand: 'VLIDECommand:Command: TestNthsswapnth: 11341072replase: 11341546nth-replace: 11341621replace: 11341769replase_1: 11341891replase_2: 11342038Finished: 11342197Lowest number for results is the fastest:swapnth = 474replase = 75nth-replace = 148replace = 122replase_1 = 147replase_2 = 159Command:Command: TestNthsswapnth: 11344692replase: 11345168nth-replace: 11345246replace: 11345398replase_1: 11345538replase_2: 11345685Finished: 11345851Lowest number for results is the fastest:swapnth = 476replase = 78nth-replace = 152replace = 140replase_1 = 147replase_2 = 166Command:Command: TestNthsswapnth: 11350462replase: 11350933nth-replace: 11351009replace: 11351155replase_1: 11351276replase_2: 11351423Finished: 11351581Lowest number for results is the fastest:swapnth = 471replase = 76nth-replace = 146replace = 121replase_1 = 147replase_2 = 158Command:Command: TestNthsswapnth: 11352441replase: 11352913nth-replace: 11352990replace: 11353141replase_1: 11353269replase_2: 11353420Finished: 11353582Lowest number for results is the fastest:swapnth = 472replase = 77nth-replace = 151replace = 128replase_1 = 151replase_2 = 162Command:Command: TestNthsswapnth: 11354036replase: 11354512nth-replace: 11354588replace: 11354739replase_1: 11354871replase_2: 11355021Finished: 11355184Lowest number for results is the fastest:swapnth = 476replase = 76nth-replace = 151replace = 132replase_1 = 150replase_2 = 163Command:
Command:Command: (LOAD "D:/replase.LSP") C:TESTNTHSCommand: TestNthsswapnth: 11533020replase: 11533675nth-replace: 11533829replace: 11534141replase_1: 11534278replase_2: 11534565Finished: 11534774Lowest number for results is the fastest:swapnth = 655replase = 154nth-replace = 312replace = 137replase_1 = 287replase_2 = 209Command:Command: TestNthsswapnth: 11535754replase: 11540417nth-replace: 11540575replace: 11540888replase_1: 11541032replase_2: 11541324Finished: 11541538Lowest number for results is the fastest:swapnth = 4663replase = 158nth-replace = 313replace = 144replase_1 = 292replase_2 = 214Command:Command: TestNthsswapnth: 11541771replase: 11542436nth-replace: 11542590replace: 11542902replase_1: 11543051replase_2: 11543344Finished: 11543559Lowest number for results is the fastest:swapnth = 665replase = 154nth-replace = 312replace = 149replase_1 = 293replase_2 = 215Command:Command: TestNthsswapnth: 11543785replase: 11544473nth-replace: 11544641replace: 11544969replase_1: 11545104replase_2: 11545421Finished: 11545646Lowest number for results is the fastest:swapnth = 688replase = 168nth-replace = 328replace = 135replase_1 = 317replase_2 = 225Command:Command: TestNthsswapnth: 11545831replase: 11550502nth-replace: 11550670replace: 11550990replase_1: 11551142replase_2: 11551450Finished: 11551669Lowest number for results is the fastest:swapnth = 4671replase = 168nth-replace = 320replace = 152replase_1 = 308replase_2 = 219Command:
;;================================================================= ;; ;; 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
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>
Command: testElapsed 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: testElapsed 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: testElapsed 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>
(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") ) ))
;; 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)))) )
(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") ) ))
Command: testElapsed 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: testElapsed 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>
(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") ) ))
Command: testElapsed 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: testElapsed 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>
In your recursive routine, it stops when the replacement is made so in that testit stopped after 6 iterations.
No, sorry, I was too lazy.
(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
;; 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)
Command:Command: (LOAD "E:/test.LSP") C:TESTCommand: testI = 99Elapsed 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 = 199Elapsed 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 = 299Elapsed 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 = 399Elapsed 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 = 499Elapsed 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 = 599Elapsed 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 = 699Elapsed 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 = 799Elapsed 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 = 899Elapsed 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 = 999Elapsed 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>1099Command:
Command:Command: (LOAD "E:/test.VLX") nilCommand: testI = 99Elapsed 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 = 199Elapsed 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 = 299Elapsed 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 = 399Elapsed 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 = 499Elapsed 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 = 599Elapsed 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 = 699Elapsed 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 = 799Elapsed 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 = 899Elapsed 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 = 999Elapsed 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>1099Command:
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.
(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
Command: (LOAD "E:/test_1.LSP") C:TESTCommand: testI = 99Elapsed 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 = 199Elapsed 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 = 299Elapsed 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 = 399Elapsed 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 = 499Elapsed 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 = 599Elapsed 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 = 699Elapsed 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 = 799Elapsed 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 = 899Elapsed 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 = 999Elapsed 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>1099Command:
Command:Command: (LOAD "E:/test_1.VLX") nilCommand: testI = 99Elapsed 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 = 199Elapsed 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 = 299Elapsed 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 = 399Elapsed 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 = 499Elapsed 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 = 599Elapsed 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 = 699Elapsed 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 = 799Elapsed 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 = 899Elapsed 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 = 999Elapsed 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>1099Command: