- ;计时器开始******************
- (defun cx-jsq ()
- (setq time_tmp (getvar "TDUSRTIMER"))
- )
- (defun cx-end-jsq ()
- (setq time_tmp (- (getvar "TDUSRTIMER") time_tmp)
- time_tmp (* time_tmp 86400)
- )
- (prompt (strcat "用时" (rtos time_tmp 2 4) "秒"))
- (setq time_tmp nil)
- (princ)
- )
- ;准备测试数据
- (defun c:tx1()
- (cx-jsq)
- (setq all_lst1 nil)
- (setq lst '((1 "a") (2 "b") (3 "c")))
- (repeat 100000 ;10w个原子
- (setq all_lst1(cons lst all_lst1))
- )
- (cx-end-jsq)
- (princ)
- )
- ;开始测试,都让他们删除掉“0”开头的数据
- ;mapcar
- (defun c:tt1()
- (cx-jsq)
- (setq all_lst all_lst1)
- (setq lstx1 nil)
- (mapcar '(lambda(x) (if(= 1 (car x)) (setq lstx1 (cons x lstx1))))all_lst)
- (cx-end-jsq)
- (princ)
- )
- ;l-remove-if-not
- (defun c:tt2()
- (cx-jsq)
- (setq all_lst all_lst1)
- (setq lstx2 nil)
- (setq lstx2(vl-remove-if-not '(lambda(x) (= 1 (car x))) all_lst))
- (cx-end-jsq)
- (princ)
- )
- ;repeat
- (defun c:tt3()
- (cx-jsq)
- (setq all_lst all_lst1)
- (setq lstx3 nil)
- (setq n (length all_lst))
- (repeat n
- (setq x (car all_lst))
- (if(= 1(car x)) (setq lstx3 (cons x lstx3)))
- (setq all_lst (cdr all_lst))
- )
- (cx-end-jsq)
- (princ)
- )
- ;while
- (defun c:tt4()
- (cx-jsq)
- (setq all_lst all_lst1)
- (setq lstx4 nil)
- (setq n (length all_lst))
- (while (setq x (car all_lst))
- (if(= 1(car x)) (setq lstx4 (cons x lstx4)))
- (setq all_lst (cdr all_lst))
- )
- (cx-end-jsq)
- (princ)
- )
- ;foreach
- (defun c:tt5()
- (cx-jsq)
- (setq all_lst all_lst1)
- (setq lstx4 nil)
- (setq n (length all_lst))
- (foreach x all_lst
- (if(= 1(car x)) (setq lstx5 (cons x lstx5)))
- )
- (cx-end-jsq)
- (princ)
- )
第一遍测试
命令: tx1 用时0.064秒
命令:
命令: tt1 用时0.078秒
命令:
命令: tt2 用时0.065秒
命令:
命令: tt3 用时0.088秒
命令:
命令: tt4 用时0.096秒
命令:
命令: tt5 用时0.098秒
第二遍测试
命令: tx1 用时0.052秒
命令:
命令: tt1 用时0.058秒
命令:
命令: tt2 用时0.065秒
命令:
命令: tt3 用时0.092秒
命令:
命令: tt4 用时0.046秒
命令:
命令: tt5 用时0.069秒 |