(setq hasMilliSecs (/= (getvar "MILLISECS") nil))
(setvar "LOGFILEMODE" 0)
(vl-load-com)

(if vlisp-optimiser (vlisp-optimiser nil)) ;; disable VLisp-Optimiser, if present

(defun t_vla_fastcom_add3dpoly ( count fptr / doc ms sa points time1 time2 time3 time4 )

  ;;--- build data list
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq ms (vla-get-modelspace doc))
  (setq sa (vlax-make-safearray vlax-vbDouble (cons 0 8)))
  (vlax-safearray-fill sa '(0 1 2  3 4 5  6 7 8))
  (setq points (vlax-make-variant sa))

  ;;--- now run test : VLA (default)
  (if lisp$enablefastcom (lisp$enablefastcom nil)) ;; disable FAST COM, if present
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (repeat (* count count)
    (vla-add3dpoly ms points)
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))

  ;;--- cleanup
  (command "_erase" "_all" "")

  ;;--- now run test : VLA (fast COM)
  (if lisp$enablefastcom (lisp$enablefastcom t)) ;; enable FAST COM, if present
  (setq time3 (getvar "MILLISECS"))
  (if (not time3) (setq time3 (getvar "TDUSRTIMER")))
  (if (not time3) (setq time3 0.0))

  (repeat (* count count)
    (vla-add3dpoly ms points)
  )

  (setq time4 (getvar "MILLISECS"))
  (if (not time4) (setq time4 (getvar "TDUSRTIMER")))
  (if (not time4) (setq time4 0.0))

  ;;--- cleanup
  (command "_erase" "_all" "")
  ;;--- test results
  (setq bench$secsNorm (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (setq bench$secsFast (if hasMilliSecs (* 0.001 (- time4 time3)) (* 86400.0 (- time4 time3))))
  (setq bench$seconds (+ bench$secsNorm bench$secsFast))

  (princ (strcat "* VLA-ADD3DPOLY (default) : " (rtos bench$secsNorm 2 3) "  (fast COM) : " (rtos bench$secsFast 2 3) "\n"))
  (if fptr
    (princ (strcat "* VLA-ADD3DPOLY (default) : " (rtos bench$secsNorm 2 3) "  (fast COM) : " (rtos bench$secsFast 2 3) "\n") fptr)
  )

  bench$seconds
)

;; to increase/decrease the number of bench loops : > 1 increase < 1 decrease
(if (not $benchcyclesfactor) (setq $benchcyclesfactor 1))

;; to run this loaded test manually
(defun C:Run ()
  (setvar "cmdecho" 0)
  (print)
  (t_vla_fastcom_add3dpoly (* 75 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
