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

(defun t_vlfilerename ( count fptr / time1 time2 tmppath tmpdst tmpdst tfptr )

  ;;-----------------------------
  (setq tmppath (getenv "TMP"))
  (if (not tmppath) (setq tmppath (getenv "TEMP")))

  (setq tmpsrc (strcat tmppath "\\vl-file-rename.###.0"))
  (setq tmpdst (strcat tmppath "\\vl-file-rename.###.1"))

  (vl-file-delete tmpsrc)
  (vl-file-delete tmpdst)

  (setq tfptr (open tmpsrc "w"))
  (write-line "dummy" tfptr)
  (close tfptr)
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (repeat (* count count)
    (vl-file-rename tmpsrc tmpdst)
    (vl-file-rename tmpdst tmpsrc)
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;-----------------------------
  (vl-file-delete tmpsrc)
  (vl-file-delete tmpdst)
  ;;-----------------------------
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* VL-FILE-RENAME : " (rtos bench$seconds 2 3) "\n"))
  (if fptr                                     
    (princ (strcat "* VL-FILE-RENAME : " (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_vlfilerename (* 50 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
