;;;开发过程,图元多时对速度要求较高,特写此程序测试
;;;师兄:QQ 361865648
;;;实验结果:vl-remove-if最快,foreach次之
;;;repeat和while每次都一样
;;;repeat表条件筛选速度测试,参考:15.75 秒
(defun c:tt1 (/ s seconds lst mylst i s2 seconds2)
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
(setq lst (ATOMS-FAMILY 1))
(setq n(length lst) lst1 lst)
(repeat 1000
(setq i 0
mylst nil
lst1 lst
)
(repeat n
;(setq thisitm (nth i lst)
; i (1+ i)
;)
(setq thisitm (car lst1) lst1 (cdr lst1))
(if (= "A" (substr thisitm 1 1))
(setq mylst (cons thisitm mylst))
)
)
)
(setq mylst (REVERSE ylst));_这行对速度基本没影响
(setq s2 (getvar "DATE"))
(setq seconds2 (* 86400.0 (- s2 (fix s2))))
(princ
(strcat "\ntt1 Repeat 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
;(defun c:tt1 (/ s seconds lst mylst i s2 seconds2)
; (setq s (getvar "DATE"))
; (setq seconds (* 86400.0 (- s (fix s))))
; (setq lst (ATOMS-FAMILY 1))
; (setq n(length lst))
; (repeat 100
; (setq i 0
; mylst nil
; )
; (repeat n
; (setq thisitm (nth i lst)
; i (1+ i)
; )
; (if (= "A" (substr thisitm 1 1))
; (setq mylst (cons thisitm mylst))
; )
; )
; )
; (setq mylst (REVERSE ylst));_这行对速度基本没影响
; (setq s2 (getvar "DATE"))
; (setq seconds2 (* 86400.0 (- s2 (fix s2))))
; (princ
; (strcat "\n tt1 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
; )
;)
;;;vl-remove-if-not表条件筛选速度测试 参考:11.79 秒
(defun c:tt2 (/ s seconds lst mylst s2 seconds2)
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
(setq lst (ATOMS-FAMILY 1))
(repeat 1000
(setq mylst (vl-remove-if
'(lambda (x)
(/= "A" (substr x 1 1))
)
lst
)
)
)
(setq s2 (getvar "DATE"))
(setq seconds2 (* 86400.0 (- s2 (fix s2))))
(princ
(strcat "\ntt2 Vl-Remove-If 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
;;;foreach表条件筛选速度测试 参考:14.36 秒
(defun c:tt3 (/ s seconds lst mylst itm s2 seconds2)
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
(setq lst (ATOMS-FAMILY 1))
(repeat 1000
(setq mylst nil)
(foreach itm lst
(if (= "A" (substr itm 1 1))
(setq mylst (cons itm mylst))
)
)
)
(setq mylst (REVERSE mylst));_这行对速度基本没影响
(setq s2 (getvar "DATE"))
(setq seconds2 (* 86400.0 (- s2 (fix s2))))
(princ
(strcat "\ntt3 Foreach 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
;;;while表条件筛选速度测试,每次和tt1都一样:17.15 秒
(defun c:tt4 (/ i len s seconds lst mylst itm s2 seconds2)
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
(setq lst (ATOMS-FAMILY 1))
(setq len(length lst) )
(repeat 1000
(setq mylst nil i 0 lst1 lst)
(while (< i len)
;(setq itm(nth i lst))
(setq itm (car lst1) lst1 (cdr lst1))
(if (= "A" (substr itm 1 1))
(setq mylst (cons itm mylst))
)
(setq i(1+ i))
)
)
(setq mylst (REVERSE mylst));_这行对速度基本没影响
(setq s2 (getvar "DATE"))
(setq seconds2 (* 86400.0 (- s2 (fix s2))))
(princ
(strcat "\ntt4 While 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
;(defun c:tt4 (/ i len s seconds lst mylst itm s2 seconds2)
; (setq s (getvar "DATE"))
; (setq seconds (* 86400.0 (- s (fix s))))
; (setq lst (ATOMS-FAMILY 1))
; (setq len(length lst) )
; (repeat 100
; (setq mylst nil i 0)
;
; (while (< i len)
; (setq itm(nth i lst))
; (if (= "A" (substr itm 1 1))
; (setq mylst (cons itm mylst))
; )
; (setq i(1+ i))
; )
; )
; (setq mylst (REVERSE mylst));_这行对速度基本没影响
; (setq s2 (getvar "DATE"))
; (setq seconds2 (* 86400.0 (- s2 (fix s2))))
; (princ
; (strcat "\ntt3 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
; )
;)
;;;mapcar表条件筛选速度测试,每次和tt1都一样:11.68 秒
(defun c:tt5 (/ i len s seconds lst mylst itm s2 seconds2)
(setq s (getvar "DATE"))
(setq seconds (* 86400.0 (- s (fix s))))
(setq lst (ATOMS-FAMILY 1))
(setq len(length lst) )
(repeat 1000
(setq mylst nil i 0 )
(mapcar '(lambda (itm)
(if (= "A" (substr itm 1 1))
(setq mylst (cons itm mylst))
)
)
lst)
)
(setq mylst (REVERSE mylst));_这行对速度基本没影响
(setq s2 (getvar "DATE"))
(setq seconds2 (* 86400.0 (- s2 (fix s2))))
(princ
(strcat "\ntt5 Mapcar 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
(c:tt1)
(c:tt2)
(c:tt3)
(c:tt4)
(c:tt5)
(prin1)