本帖最后由 xugaoming23 于 2020-4-21 01:39 编辑
原以为foreach是执行效率最低的,结果不知道怎么回事,在循环8000次时,嵌套函数、mapcar都卡死了,只有foreach存活。
 -
- (defun XGM:timestart( )
- (setq *t1* (getvar "DATE"))
- )
- (defun XGM:timeend( / s)
- (print (rtos (* 86400.0 (- (setq s (- (getvar "date") *t1*)) (fix s))) 2 2))
- )
- (setq *tt (getint "请输入循环次数:"))
- (defun c:t1 (/ i j lst11 lst22 math:lstcj)
- ;嵌套函数
- (defun math:lstcj(lst1 lst2)
- (if lst2
- (math:lstcj (vl-remove (car lst2) lst1) (cdr lst2))
- lst1
- )
- )
- (setq i 0 j 5 lst11 nil lst22 nil)
- (repeat *tt
- (setq lst11 (cons (setq i (1+ i )) lst11 ))
- (setq lst22 (cons (setq j (1+ j )) lst22 ))
- )
- (XGM:timestart)
- (math:lstcj lst11 lst22)
- (XGM:timeend)
- )
-
- (defun c:t2(/ i j lst11 lst22 math:lstcj)
- ;mapcar形式
- (defun math:lstcj(lst1 lst2)
- (mapcar '(lambda (x)(setq lst1 (vl-remove x lst1))) lst2)
- lst1
- )
- (setq i 0 j 5 lst11 nil lst22 nil)
- (repeat *tt
- (setq lst11 (cons (setq i (1+ i )) lst11 ))
- (setq lst22 (cons (setq j (1+ j )) lst22 ))
- )
- (XGM:timestart)
- (math:lstcj lst11 lst22)
- (XGM:timeend)
- )
-
- (defun c:t3(/ i j lst11 lst22 math:lstcj)
- ;foreach形式
- (defun math:lstcj(lst1 lst2)
- (foreach x lst2 (setq lst1 (vl-remove x lst1)))
- )
- (setq i 0 j 5 lst11 nil lst22 nil)
- (repeat *tt
- (setq lst11 (cons (setq i (1+ i )) lst11 ))
- (setq lst22 (cons (setq j (1+ j )) lst22 ))
- )
- (XGM:timestart)
- (math:lstcj lst11 lst22)
- (XGM:timeend)
- )
|