(vl-load-com)
(setvar "LOGFILEMODE" 0)

(setq g_dbl nil)
(setq g_str nil)
(setq g_int nil)

(defun t_gcintensive ( count fptr / time1 time2 lst ctr tmp )
  (setq g_dbl (list 3.0 2.0 1.0 0.0 4.0 5.0 6.0 7.0 8.0 9.0)) ;; 10
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 20
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 40
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 80
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 160
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 320
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 640
  (setq g_dbl (append g_dbl (reverse g_dbl)))   ;; 1280

  (setq g_str (list "aaaaa" "bbbbb" "ccccc" "ddddd" "eeeee" "fffff" "ggggg" "hhhhh"))
  (setq g_str (append g_str (reverse g_str)))   ;; 16
  (setq g_str (append g_str (reverse g_str)))   ;; 32
  (setq g_str (append g_str (reverse g_str)))   ;; 64
  (setq g_str (append g_str (reverse g_str)))   ;; 128
  (setq g_str (append g_str (reverse g_str)))   ;; 256
  (setq g_str (append g_str (reverse g_str)))   ;; 512
  (setq g_str (append g_str (reverse g_str)))   ;; 1024
  (setq g_str (append g_str (reverse g_str)))   ;; 2048
  (setq g_str (append g_str (reverse g_str)))   ;; 4096

  (setq g_int (list 0 1 2 3 4 5 6 7 8 9))       ;; 10
  (setq g_int (append g_int (reverse g_int)))   ;; 20
  (setq g_int (append g_int (reverse g_int)))   ;; 40
  (setq g_int (append g_int (reverse g_int)))   ;; 80
  (setq g_int (append g_int (reverse g_int)))   ;; 160
  (setq g_int (append g_int (reverse g_int)))   ;; 320
  (setq g_int (append g_int (reverse g_int)))   ;; 640
  (setq g_int (append g_int (reverse g_int)))   ;; 1280
  (setq g_int (append g_int (reverse g_int)))   ;; 2560
  (setq g_int (append g_int (reverse g_int)))   ;; 5120
  (setq g_int (append g_int (reverse g_int)))   ;; 10240

  (repeat 1000
    (setq g_doubles (cons g_dbl g_doubles))
    (setq g_strings (cons g_str g_strings))
    (setq g_numbers (cons g_int g_numbers))
  )

  ;;-----------------------------
  (setq time1 (getvar "TDUSRTIMER"))

  (setq ctr 0)
  (repeat count
    (setq lst (list g_dbl g_str g_int 1 2 3 1.0 2.0 3.0 "xxxxx" "yyyyy" "zzzzz"))

    (repeat count
      (list g_dbl g_str g_int 7 8 9 7.0 8.0 9.0 "11111" "22222" "33333")
      (setq tmp (cons (rtos (+ ctr 0.1) 2 4) tmp))
      (gc)
      (setq ctr (1+ ctr))
    )

    (setq lst nil)
  )

  (setq time2 (getvar "TDUSRTIMER"))
  (if (not time1) (setq time1 0.0))
  (if (not time2) (setq time2 0.0))
  ;;-----------------------------
(print (length g_dbl))  ;; 1280
(print (length g_str))  ;; 4096
(print (length g_int))  ;; 10240
(print ctr)
(print)
  ;;-----------------------------
  (setq bench$seconds (* 86400.0 (- time2 time1)))
  (princ (strcat "* GC (intensive) : " (rtos bench$seconds 2 3) "\n"))
  (if fptr
    (princ (strcat "* GC (intensive) : " (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_gcintensive (* 200 $benchcyclesfactor) nil)
  (setvar "cmdecho" 1)
  (princ)
)
