Author Topic: Functions append cons and vl-list*  (Read 3815 times)

0 Members and 1 Guest are viewing this topic.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Functions append cons and vl-list*
« on: December 02, 2003, 07:55:40 AM »
Heres a little testing I did on the speed of the functions append cons & vl-list*
Code: [Select]

;;; 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")
  )
TheSwamp.org  (serving the CAD community since 2003)

rugaroo

  • Bull Frog
  • Posts: 378
  • The Other CAD Guy
Functions append cons and vl-list*
« Reply #1 on: December 02, 2003, 09:39:32 AM »
Here are my results:

(repeat 10 (testcons))

Timed testcons-repeat: 0.359000
Timed testcons-mapcar: 0.609009
Timed testcons-repeat: 0.672014
Timed testcons-mapcar: 1.032020
Timed testcons-repeat: 0.672014
Timed testcons-mapcar: 0.749986
Timed testcons-repeat: 0.484970
Timed testcons-mapcar: 1.046021
Timed testcons-repeat: 0.609009
Timed testcons-mapcar: 0.860023
Timed testcons-repeat: 0.561976
Timed testcons-mapcar: 0.938036
Timed testcons-repeat: 0.453025
Timed testcons-mapcar: 1.188004
Timed testcons-repeat: 0.500017
Timed testcons-mapcar: 0.999995
Timed testcons-repeat: 0.452985
Timed testcons-mapcar: 0.969015
Timed testcons-repeat: 0.452985
Timed testcons-mapcar: 1.406027

(repeat 10 (testvl-list))

Timed testvl-list-repeat: 0.562017
Timed testvl-list-mapcar: 0.171997
Timed testvl-list-repeat: 0.703999
Timed testvl-list-mapcar: 0.359000
Timed testvl-list-repeat: 0.530997
Timed testvl-list-mapcar: 0.203016
Timed testvl-list-repeat: 0.516030
Timed testvl-list-mapcar: 0.202976
Timed testvl-list-repeat: 0.422005
Timed testvl-list-mapcar: 0.233996
Timed testvl-list-repeat: 0.359000
Timed testvl-list-mapcar: 0.281028
Timed testvl-list-repeat: 0.390986
Timed testvl-list-mapcar: 0.328986
Timed testvl-list-repeat: 0.577989
Timed testvl-list-mapcar: 0.499977
Timed testvl-list-repeat: 0.436972
Timed testvl-list-mapcar: 0.639988
Timed testvl-list-repeat: 0.687021
Timed testvl-list-mapcar: 0.718001


Looks like I'm a little slow, and in more than one way :).
LDD06-09 | C3D 04-19 | Infraworks 360 | VS2012-VS2017