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

(if (and (not vle-vector-midpoint) (findfile "vle-extension.lsp")) (load "vle-extension.lsp"))

(defun emul-vector-midpoint ( pnt1  pnt2 / pz1 pz2 )
  (if (or (not (car pnt1)) (not (cadr pnt1))) (exit))
  (if (or (not (car pnt2)) (not (cadr pnt2))) (exit))
  (setq pz1 (if (caddr pnt1) (caddr pnt1) 0.0))
  (setq pz2 (if (caddr pnt2) (caddr pnt2) 0.0))
  (list (* (+ (car pnt1) (car pnt2)) 0.5) (* (+ (cadr pnt1) (cadr pnt2)) 0.5) (* (+ pz1 pz2) 0.5))
)

(defun t_vle_vector_midpoint ( count fptr / p1 p2 time1 time2 time3 time4 )

  ;;--- build data list
  (setq p1 '(22.0 33.0) p2 '(33.0 44.0 55.0))

  ;;--- now run test : NORMAL
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (repeat (* count count)
    (emul-vector-midpoint p1 p2)
    (emul-vector-midpoint p2 p1)
  )

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

  ;;--- now run test : VLE
  (setq time3 (getvar "MILLISECS"))
  (if (not time3) (setq time3 (getvar "TDUSRTIMER")))
  (if (not time3) (setq time3 0.0))

  (repeat (* count count)
    (vle-vector-midpoint p1 p2)
    (vle-vector-midpoint p2 p1)
  )

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

  ;;--- 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 "* (Standard) : " (rtos bench$secsNorm 2 3) "  VLE-VECTOR-MIDPOINT : " (rtos bench$secsFast 2 3) "\n"))
  (if fptr
    (princ (strcat "* (Standard) : " (rtos bench$secsNorm 2 3) "  VLE-VECTOR-MIDPOINT : " (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_vle_vector_midpoint (* 400 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
