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

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

  (repeat (* count count)
      (atoms-family 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 "* ATOMS-FAMILY 0 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* ATOMS-FAMILY 0 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

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

  (repeat count
    (repeat (1- count)
      (atoms-family 0 '("CAR" "CDR" "XYZ"))
    )
  )

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

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

  (repeat count
    (repeat (1- count)
      (atoms-family 1)
    )
  )

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

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

  (repeat count
    (repeat (1- count)
      (atoms-family 1 '("CAR" "CDR" "XYZ"))
    )
  )

  (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 "* ATOMS-FAMILY 1 (Refs) : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* ATOMS-FAMILY 1 (Refs) : " (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_atoms0     (*  25 $benchcyclesfactor) nil)
  (t_atoms1     (*  25 $benchcyclesfactor) nil)
  (t_atoms0refs (* 500 $benchcyclesfactor) nil)
  (t_atoms1refs (* 500 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
