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

(defun t_safearray ( count fptr / time1 time2 )
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (repeat (* count count)
      (safearray vlax-vbBoolean '(0 . 1))
      (safearray vlax-vbBoolean '(1 . 2) '(2 . 4))
      (safearray vlax-vbString  '(0 . 1))
      (safearray vlax-vbString  '(1 . 2) '(2 . 4))
      (safearray vlax-vbSingle  '(0 . 3))
      (safearray vlax-vbSingle  '(0 . 1) '(2 . 4))
      (safearray vlax-vbDouble  '(0 . 3))
      (safearray vlax-vbDouble  '(0 . 3) '(0 . 3))
      (safearray vlax-vbInteger '(1 . 4))
      (safearray vlax-vbInteger '(1 . 4) '(0 . 2))
      (safearray vlax-vbLong    '(2 . 5))
      (safearray vlax-vbLong    '(0 . 1) '(1 . 3))
      (safearray vlax-vbVariant '(2 . 4))
      (safearray vlax-vbVariant '(1 . 2) '(2 . 4))
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;-----------------------------
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "*           SAFEARRAY : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "*           SAFEARRAY : " (rtos bench$seconds 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_safearray (* 200 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
