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

(defun CreateAndEraseManyLines ( nCount / ss lst )

  (princ (strcat "\n* Creating " (itoa nCount) " entities ..."))

  (setq lst '((0 . "POINT")(10 0 0 0)))
  (repeat nCount
    (entmakex lst)
  )

  (princ "\n* and erase all ... ")
  (setq ss (ssget "X"))
  (command "_erase" ss "")

  (princ " done.\n")
  (princ)
)

(defun t_ssget_erased ( count fptr / time1 time2 ss )
  ;;-----------------------------
  (command "_line" '( 0 0) '(1 1) '(2 0) '(3 1) "")
  (gc)  ;; to free all selection sets
  ;;-----------------------------
  (setq time1 (getvar "MILLISECS"))
  (if (not time1) (setq time1 (getvar "TDUSRTIMER")))
  (if (not time1) (setq time1 0.0))

  (repeat count
    (ssget "X")
  )

  (setq time2 (getvar "MILLISECS"))
  (if (not time2) (setq time2 (getvar "TDUSRTIMER")))
  (if (not time2) (setq time2 0.0))
  ;;-----------------------------
  (setq ss (ssget "X"))
  (command "_erase" ss "") (setq ss nil)
  ;;-----------------------------
  (setq bench$seconds (if hasMilliSecs (* 0.001 (- time2 time1)) (* 86400.0 (- time2 time1))))
  (princ (strcat "* SSGET : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* SSGET : " (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_ssget_erased (* 2000 $benchcyclesfactor) nil)

  (CreateAndEraseManyLines 100000)

  (princ "\n* Run (ssget) test again ...\n")
  (t_ssget_erased (* 2000 $benchcyclesfactor) nil)

  (setvar "cmdecho" 1)
  (princ)
)
