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

(if vlisp-optimiser (vlisp-optimiser nil)) ;; disable VLisp-Optimiser, if present
(defun cdr-assoc-entget ( count ename )
  (repeat (* count count)
    (cdr (assoc 370 (entget ename)))
  )
)

(if vlisp-optimiser (vlisp-optimiser t)) ;; enable VLisp-Optimiser, if present
(defun cdr-assoc-entget-opt ( count ename )
  (repeat (* count count)
    (cdr (assoc 370 (entget ename)))
  )
)

(defun t_opt_cdr_assoc_entget ( count fptr / ename elist time1 time2 time3 time4 time5 time6 )

  ;;--- build data list
  (setq elist '((0 . "LINE") (8 . "0") (62 . 4) (10 0 0 0) (11 10 10 10) (370 . 100)))
  (entmake elist)
  (setq ename (entlast))

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

  (cdr-assoc-entget count ename)

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))

  ;;--- now run test : optimised
  (setq time3 (getvar "MILLISECS"))
  (if (not time3) (setq time3 (getvar "TDUSRTIMER")))
  (if (not time3) (setq time3 0.0))

  (cdr-assoc-entget-opt count ename)

  (setq time4 (getvar "MILLISECS"))
  (if (not time4) (setq time4 (getvar "TDUSRTIMER")))
  (if (not time4) (setq time4 0.0))

  ;;--- test results
  (setq bench$secsNorm (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (setq bench$secsFast (if hasMilliSecs (* 0.001 (- time4 time3)) (* 86400.0 (- time4 time3))))
  (setq bench$seconds (+ bench$secsNorm bench$secsFast))
  ;;-----------------------------
  (entdel ename)
  ;;-----------------------------

  (princ (strcat "* (cdr (assoc (entget x ename))) : " (rtos bench$secsNorm 2 3) "  optimised : " (rtos bench$secsFast 2 3) "\n"))
  (if fptr
    (princ (strcat "* (cdr (assoc (entget x ename))) : " (rtos bench$secsNorm 2 3) "  optimised : " (rtos bench$secsFast 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_opt_cdr_assoc_entget (* 300 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
