(setq hasMilliSecs (/= (getvar "MILLISECS") nil))
(setvar "LOGFILEMODE" 0)

(defun t_mul ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (* res i 1.0)
    )
  )

  (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 "* FLT MUL : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT MUL : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_mul2 ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (* res i)
    )
  )

  (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 "* FLT MUL 2 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT MUL 2 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

;;===============================================

(defun t_div ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (/ res i 1.0)
    )
  )

  (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 "* FLT DIV : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT DIV : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_div2 ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (/ res i)
    )
  )

  (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 "* FLT DIV 2 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT DIV 2 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

;;===============================================

(defun t_add ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (+ res i 1.0)
    )

  )

  (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 "* FLT ADD : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT ADD : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_add2 ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (+ res i)
    )
  )

  (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 "* FLT ADD 2 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT ADD 2 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

;;===============================================

(defun t_sub ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (- res i 1.0)
    )
  )

  (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 "* FLT SUB : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT SUB : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_sub2 ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (* i 1.0))  ;; make a float
    (repeat (1- i)
      (- res i)
    )
  )

  (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 "* FLT SUB 2 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT SUB 2 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

;;===============================================

(defun t_add1 ( count fptr / i time1 time2 res )
  (setq i 1)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (while (< i count)
    (setq i (1+ i)) 
    (setq res (+ i 0.0))  ;; make a float
    (repeat (- i 1)
      (1+ res)
    )
  )

  (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 "* FLT ADD 1 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT ADD 1 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

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

  (while (> i 0)
    (setq i (1- i)) 
    (setq res (- i 0.0))  ;; make a float
    (repeat (- i 1)
      (1- res)
    )
  )

  (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 "* FLT SUB 1 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* FLT SUB 1 : " (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 ( / sum )
  (setvar "cmdecho" 0)
  (setq sum 0.0)
  (print)
  (setq sum (+ sum (t_mul  (* 1000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_add  (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_div  (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_sub  (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_add1 (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_sub1 (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_mul2 (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_add2 (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_sub2 (* 2000 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_div2 (* 2000 $benchcyclesfactor) nil)))
  (setvar "cmdecho" 1)
  (princ (strcat "\n* FLT Total : " (rtos sum 2 3) "\n"))
  (princ)
)
