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

(if (and (not vle-entget-massoc) (findfile "vle-extension.lsp")) (load "vle-extension.lsp"))

(defun emul-entget-massoc ( dxf ent )
  (mapcar 'cdr (vl-remove-if-not '(lambda (item) (eq dxf (car item))) (entget ent)))
)

(defun t_vle_entget_massoc ( count fptr / elist lastent time1 time2 time3 time4 )

  ;;--- build data list
  (setq elist '((0 . "LWPOLYLINE") (100 . "AcDbEntity") (8 . "0") (100 . "AcDbPolyline")
                (90 . 4) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0)
                (10  0.0  0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)
                (10 10.0 10.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)
                (10 20.0  0.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)
                (10 30.0 10.0) (40 . 0.0) (41 . 0.0) (42 . 0.0)
                (210 0.0 0.0 1.0)))
  (setq lastent (entmakex elist))

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

  (repeat (* count count)
    (emul-entget-massoc 10 lastent)
    (emul-entget-massoc 40 lastent)
  )

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

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

  (repeat (* count count)
    (vle-entget-massoc 10 lastent)
    (vle-entget-massoc 40 lastent)
  )

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

  ;;--- test cleanup
  (entdel lastent);

  ;;--- 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))

  (princ (strcat "* (Standard) : " (rtos bench$secsNorm 2 3) "  VLE-ENTGET-MASSOC : " (rtos bench$secsFast 2 3) "\n"))
  (if fptr
    (princ (strcat "* (Standard) : " (rtos bench$secsNorm 2 3) "  VLE-ENTGET-MASSOC : " (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_vle_entget_massoc (* 100 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
