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

(setq g_ctr 0)
(defun rxcb ( arg1 arg2 arg3 )
;;  (setq g_ctr (1+ g_ctr))  ;; for testing only
;;  (print "--- cb ---")     ;; for testing only
;;  (print arg1)             ;; for testing only
;;  (print arg2)             ;; for testing only
;;  (print arg3)             ;; for testing only
  (princ)
)

(setq g_vlaenlist NIL)
(defun makeObjectsAndReactors ( num / cad doc ms pt vlaen ms rx entlist )
  (setq cad (vlax-get-acad-object))
  (setq doc (vla-get-activedocument cad))
  (setq ms  (vla-get-modelspace doc))
  (setq pt  (vlax-3d-point 0 0 0))

  (repeat num
    (setq vlaen (vla-addpoint ms pt))
    (setq entlist (cons vlaen entlist))
  )
  (setq rx (vlr-object-reactor entlist nil '((:vlr-modified . rxcb))))

  entlist
)

(defun t_vlr_obj_rx ( count fptr / time1 time2 color vlaen )

  ;; create 1000 entities + add 1 single ObjectReactor to each entity
  (if (not g_vlaenlist)
    (setq g_vlaenlist (makeObjectsAndReactors 1000))
  )
  (setq color 0)

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

  (repeat count
    (foreach vlaen g_vlaenlist
      (vla-put-color vlaen (setq color (1+ color)))
      (if (> color 250) (setq color 0))
    )
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;-----------------------------
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* VLR-ObjectReactor : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* VLR-ObjectReactor : " (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_vlr_obj_rx (* 20 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
