repeat vl-remove-if foreach while条件过滤速度测试
本帖最后由 caiqs 于 2014-4-8 22:11 编辑不知道售价是干什么,论坛就是开放的最好,何必给新人那么多的限制
;;;开发过程,图元多时对速度要求较高,特写此程序测试
;;;师兄:QQ 361865648
;;;实验结果:vl-remove-if最快,foreach次之
;;;repeat和while每次都一样
本帖最后由 Gu_xl 于 2014-4-8 23:04 编辑
tt1和tt4慢的原因并不在于是repeat 和while,而是在与其用了nth函数!将TT1和TT4修改一下,不用nth,速度极大提高:
(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 100
(setq i 0
mylstnil
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 "\n tt1 运行时间:" (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 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 "\ntt3 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
还可以使用mapcar函数来测试:
(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 100
(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 "\ntt3 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
)
)
修改后上述几个程序编译后运行,速度相差就不那么明显了:
tt1 运行时间:1.58 秒
tt2 运行时间:1.33 秒
tt3 运行时间:1.29 秒
tt4 运行时间:1.91 秒
tt5 运行时间:1.39 秒 传说的中师兄? 也放几个源码出来,给我等不入流之辈学习呗. tt1 运行时间:0.67 秒 tt2 运行时间:0.33 秒
tt3 运行时间:0.52 秒
tt4 运行时间:0.72 秒
tt5 运行时间:0.39 秒
我电脑速度比Gu_xl 快一倍多啊,你可以换电脑了 速度相差不明显的话就把循环次数搞大些
条件过滤即把符合条件的提取出来,也即把不符合条件的去掉,按逻辑vl-remove-if为如果...则删除,比较符合人的思维,实验证明这个也是最快的
Gu_xl 发表于 2014-4-8 22:42 static/image/common/back.gif
tt1和tt4慢的原因并不在于是repeat 和while,而是在与其用了nth函数!将TT1和TT4修改一下,不用nth,速度极大 ...
批量处理的情况用mapcar,实际使用中是较多的,在我印象中速度是比较慢的
对比没有太多的考虑,没有加入这个函数也不是特意的
没想到 nth 居然有如此影响 好久没来了!
突然发现师兄发帖哦!
必须支持下!
wowan1314 发表于 2014-4-9 11:47 static/image/common/back.gif
好久没来了!
突然发现师兄发帖哦!
必须支持下!
随便写的
难得还有人记得我,这论坛一个月也上不了几次
应该有很多认识的或以前曾聊过的人
为什么显示的名字注册了就不能改了,导致我看不出各位的身份,应该很多是QQ好友吧 caiqs 发表于 2014-4-9 12:12 static/image/common/back.gif
随便写的
难得还有人记得我,这论坛一个月也上不了几次
我已经不是 “随便的人”了! 呵呵
现在基本不碰程序了,差不多快忘光了。
论坛很少来了。偶然无聊来看看,都没登陆! 今天看你发帖才登陆上来 支持下。
页:
[1]
2