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

(defun t_nth ( count fptr / time1 time2 lst i )

  ;;--- build data list
  (setq i 0)
  (setq lst nil)
  (repeat 10000
    (setq lst (cons i lst))
    (setq i (1+ i))
  )

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

  (repeat 100
    (setq i 0)
    (repeat count
      (nth i lst)
      (setq i (1+ i))
    )
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;--- test results
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* NTH : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* NTH : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_nth_0 ( count fptr / time1 time2 lst i )

  ;;--- build data list
  (setq i 0)
  (setq lst nil)
  (repeat 10000
    (setq lst (cons i lst))
    (setq i (1+ i))
  )

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

  (repeat count * cound
    (nth 0 lst)
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;--- test results
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* NTH-0 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* NTH-0 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_nth_1 ( count fptr / time1 time2 lst i )

  ;;--- build data list
  (setq i 0)
  (setq lst nil)
  (repeat 10000
    (setq lst (cons i lst))
    (setq i (1+ i))
  )

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

  (repeat count * cound
    (nth 1 lst)
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;--- test results
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* NTH-1 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* NTH-1 : " (rtos bench$seconds 2 3) "\n") fptr)
  )
  bench$seconds
)

(defun t_nth_2 ( count fptr / time1 time2 lst i )

  ;;--- build data list
  (setq i 0)
  (setq lst nil)
  (repeat 10000
    (setq lst (cons i lst))
    (setq i (1+ i))
  )

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

  (repeat count * cound
    (nth 2 lst)
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;--- test results
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* NTH-2 : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* NTH-2 : " (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)
  (print)
  (setq sum (+ sum (t_nth   (* 1500 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_nth_0 (* 1500 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_nth_1 (* 1500 $benchcyclesfactor) nil)))
  (setq sum (+ sum (t_nth_2 (* 1500 $benchcyclesfactor) nil)))
  (setvar "cmdecho" 1)
  (princ (strcat "\n* Total : " (rtos sum 2 3) "\n"))
  (princ)
)
