(vl-load-com)
(setvar "LOGFILEMODE" 0)

(defun t_vlsort ( count fptr / time1 time2 lst )
  (setq lst (list 3 2 1 0 4 5 6 7 8 9)) ;; 10
  (setq lst (append lst (reverse lst)))   ;; 20
  (setq lst (append lst (reverse lst)))   ;; 40
  (setq lst (append lst (reverse lst)))   ;; 80
  (setq lst (append lst (reverse lst)))   ;; 160
  (setq lst (append lst (reverse lst)))   ;; 320
  (setq lst (append lst (reverse lst)))   ;; 640
  (setq lst (append lst (reverse lst)))   ;; 1280

  ;;-----------------------------
  (setq time1 (getvar "TDUSRTIMER"))

  (repeat (* count count)
    (vl-sort lst '<)
    (vl-sort lst '>)
  )

  (setq time2 (getvar "TDUSRTIMER"))
  (if (not time1) (setq time1 0.0))
  (if (not time2) (setq time2 0.0))
  ;;-----------------------------
  (setq bench$seconds (* 86400.0 (- time2 time1)))
  (princ (strcat "* VL-SORT (large list) : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* VL-SORT (large list) : " (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_vlsort (* 50 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
