Heres a little testing I did on the speed of the functions append cons & vl-list*
;;; begin timing functions by SMadsen
(defun startTimer ()
(setq time (getvar "DATE"))
)
(defun endTimer (func)
(setq time (- (getvar "DATE") time)
seconds (* 86400.0 (- time (fix time)))
)
(gc)
(outPut seconds func)
)
(defun outPut (secs def)
(gc)
(princ (strcat "\nTimed " def ": " (rtos secs 2 6)))
(princ)
)
;;; end timing functions by SMadsen
;;; testing took place in a new dwg, each time ACAD was closed
;;; and reopened
;;; testing the 'append' function
;;;
;;; this function was only run 1 time, looking at the time it took
;;; to execute you can see why.
;;;
;;; Timed testappend: 344.124989
(defun testappend (/ lst cntr)
(setq cntr 1)
(startTimer)
(repeat 50000
(setq lst (append (list cntr) lst))
(setq cntr (1+ cntr))
)
(endTimer "testappend")
)
;;; testing the 'cons' function
;;;
;;; this function was tested using (repeat 10 (testcons))
;;;
;;; Timed testcons-repeat: 0.078012
;;; Timed testcons-mapcar: 0.046992
;;; Timed testcons-repeat: 0.093019
;;; Timed testcons-mapcar: 0.078012
;;; Timed testcons-repeat: 0.078012
;;; Timed testcons-mapcar: 0.108992
;;; Timed testcons-repeat: 0.078012
;;; Timed testcons-mapcar: 0.062965
;;; Timed testcons-repeat: 0.094025
;;; Timed testcons-mapcar: 0.093985
;;; Timed testcons-repeat: 0.093985
;;; Timed testcons-mapcar: 0.109997
;;; Timed testcons-repeat: 0.093019
;;; Timed testcons-mapcar: 0.125004
;;; Timed testcons-repeat: 0.077972
;;; Timed testcons-mapcar: 0.155984
;;; Timed testcons-repeat: 0.078012
;;; Timed testcons-mapcar: 0.171997
;;; Timed testcons-repeat: 0.094025
;;; Timed testcons-mapcar: 0.171997
;;;
(defun testcons (/ lst cntr)
(setq cntr 1)
(startTimer)
(repeat 50000
(setq lst (cons cntr lst))
(setq cntr (1+ cntr))
)
(endTimer "testcons-repeat")
(repeat 50000
(setq l1 (cons cntr l1))
(setq cntr (1+ cntr))
)
(repeat 50000
(setq l2 (cons cntr l2))
(setq cntr (1+ cntr))
)
(startTimer)
(setq lst (mapcar 'cons l1 l2))
(endTimer "testcons-mapcar")
)
;;; testing the 'vl-list*' function
;;;
;;; this function was tested using (repeat 10 (testcons))
;;;
;;; Timed testvl-list-repeat: 0.093985
;;; Timed testvl-list-mapcar: 0.046992
;;; Timed testvl-list-repeat: 0.093985
;;; Timed testvl-list-mapcar: 0.061999
;;; Timed testvl-list-repeat: 0.093985
;;; Timed testvl-list-mapcar: 0.109032
;;; Timed testvl-list-repeat: 0.093985
;;; Timed testvl-list-mapcar: 0.063005
;;; Timed testvl-list-repeat: 0.094025
;;; Timed testvl-list-mapcar: 0.077972
;;; Timed testvl-list-repeat: 0.094025
;;; Timed testvl-list-mapcar: 0.108992
;;; Timed testvl-list-repeat: 0.093985
;;; Timed testvl-list-mapcar: 0.125004
;;; Timed testvl-list-repeat: 0.094025
;;; Timed testvl-list-mapcar: 0.139971
;;; Timed testvl-list-repeat: 0.093019
;;; Timed testvl-list-mapcar: 0.155984
;;; Timed testvl-list-repeat: 0.093019
;;; Timed testvl-list-mapcar: 0.171997
;;;
(defun testvl-list (/ lst cntr)
(setq cntr 1)
(startTimer)
(repeat 50000
(setq lst (vl-list* cntr lst))
(setq cntr (1+ cntr))
)
(endTimer "testvl-list-repeat")
(repeat 50000
(setq l1 (cons cntr l1))
(setq cntr (1+ cntr))
)
(repeat 50000
(setq l2 (cons cntr l2))
(setq cntr (1+ cntr))
)
(startTimer)
;; create an assocation list with VL-LIST*
(setq lst (mapcar 'vl-list* l1 l2))
(endTimer "testvl-list-mapcar")
)