明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 4147|回复: 10

[经验] repeat vl-remove-if foreach while条件过滤速度测试

[复制链接]
发表于 2014-4-8 22:10:09 | 显示全部楼层 |阅读模式
本帖最后由 caiqs 于 2014-4-8 22:11 编辑

不知道售价是干什么,论坛就是开放的最好,何必给新人那么多的限制



;;;开发过程,图元多时对速度要求较高,特写此程序测试
;;;师兄:QQ 361865648

;;;实验结果:vl-remove-if最快,foreach次之
;;;repeat和while每次都一样


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x

评分

参与人数 1明经币 +2 收起 理由
Gu_xl + 2 赞一个!

查看全部评分

发表于 2014-4-8 22:42:18 | 显示全部楼层
本帖最后由 Gu_xl 于 2014-4-8 23:04 编辑

tt1和tt4慢的原因并不在于是repeat 和while,而是在与其用了nth函数!将TT1和TT4修改一下,不用nth,速度极大提高:
  1. (defun c:tt1 (/ s seconds lst mylst i s2 seconds2)
  2.   (setq s (getvar "DATE"))
  3.   (setq seconds (* 86400.0 (- s (fix s))))
  4.   (setq lst (ATOMS-FAMILY 1))
  5.   (setq n(length lst) lst1 lst)
  6.   (repeat 100
  7.     (setq i 0
  8.     mylst  nil
  9.     lst1 lst
  10.     )
  11.     (repeat n
  12.       ;(setq thisitm (nth i lst)
  13. ;      i      (1+ i)
  14.       ;)
  15.       (setq thisitm (car lst1) lst1 (cdr lst1))
  16.       (if (= "A" (substr thisitm 1 1))
  17.   (setq mylst (cons thisitm mylst))
  18.       )
  19.     )
  20.   )
  21. (setq mylst (REVERSE ylst));_这行对速度基本没影响
  22.   (setq s2 (getvar "DATE"))
  23.   (setq seconds2 (* 86400.0 (- s2 (fix s2))))
  24.   (princ
  25.     (strcat "\n tt1 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
  26.   )
  27. )

  28. (defun c:tt4 (/ i len s seconds lst mylst itm s2 seconds2)
  29.   (setq s (getvar "DATE"))
  30.   (setq seconds (* 86400.0 (- s (fix s))))
  31.   (setq lst (ATOMS-FAMILY 1))
  32.    (setq len(length lst) )
  33.   (repeat 100
  34.     (setq mylst nil i 0 lst1 lst)
  35.    
  36.     (while (< i len)
  37.     ;(setq itm(nth i lst))
  38.       (setq itm (car lst1) lst1 (cdr lst1))
  39.       (if (= "A" (substr itm 1 1))
  40.   (setq mylst (cons itm mylst))
  41.   )
  42.       (setq i(1+ i))
  43.   )
  44.     )
  45.   (setq mylst (REVERSE mylst));_这行对速度基本没影响
  46.   (setq s2 (getvar "DATE"))
  47.   (setq seconds2 (* 86400.0 (- s2 (fix s2))))
  48.   (princ
  49.     (strcat "\ntt3 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
  50.   )
  51. )

还可以使用mapcar函数来测试:
  1. (defun c:tt5 (/ i len s seconds lst mylst itm s2 seconds2)
  2.   (setq s (getvar "DATE"))
  3.   (setq seconds (* 86400.0 (- s (fix s))))
  4.   (setq lst (ATOMS-FAMILY 1))
  5.    (setq len(length lst) )
  6.   (repeat 100
  7.     (setq mylst nil i 0 )
  8.    (mapcar '(lambda (itm)
  9.         (if (= "A" (substr itm 1 1))
  10.   (setq mylst (cons itm mylst))
  11.   )
  12.         )
  13.      lst)
  14.     )
  15.   (setq mylst (REVERSE mylst));_这行对速度基本没影响
  16.   (setq s2 (getvar "DATE"))
  17.   (setq seconds2 (* 86400.0 (- s2 (fix s2))))
  18.   (princ
  19.     (strcat "\ntt3 运行时间:" (rtos (- seconds2 seconds) 2 2) " 秒")
  20.   )
  21. )

修改后上述几个程序编译后运行,速度相差就不那么明显了:
tt1 运行时间:1.58 秒
tt2 运行时间:1.33 秒
tt3 运行时间:1.29 秒
tt4 运行时间:1.91 秒
tt5 运行时间:1.39 秒
发表于 2014-4-9 08:55:00 | 显示全部楼层
传说的中师兄? 也放几个源码出来,给我等不入流之辈学习呗.
发表于 2014-4-9 11:01:08 | 显示全部楼层
tt1 运行时间:0.67 秒
发表于 2014-4-9 11:03:34 | 显示全部楼层
tt2 运行时间:0.33 秒
tt3 运行时间:0.52 秒
tt4 运行时间:0.72 秒
tt5 运行时间:0.39 秒
我电脑速度比Gu_xl 快一倍多啊,你可以换电脑了

点评

非也!速度快慢和你系统加载的函数多少有关!  发表于 2014-4-9 11:47
 楼主| 发表于 2014-4-9 11:31:17 | 显示全部楼层
速度相差不明显的话就把循环次数搞大些

条件过滤即把符合条件的提取出来,也即把不符合条件的去掉,按逻辑vl-remove-if为如果...则删除,比较符合人的思维,实验证明这个也是最快的

 楼主| 发表于 2014-4-9 11:36:19 | 显示全部楼层
Gu_xl 发表于 2014-4-8 22:42
tt1和tt4慢的原因并不在于是repeat 和while,而是在与其用了nth函数!将TT1和TT4修改一下,不用nth,速度极大 ...

批量处理的情况用mapcar,实际使用中是较多的,在我印象中速度是比较慢的
对比没有太多的考虑,没有加入这个函数也不是特意的

没想到 nth 居然有如此影响
发表于 2014-4-9 11:47:11 | 显示全部楼层
好久没来了!
突然发现师兄发帖哦!
必须支持下!
 楼主| 发表于 2014-4-9 12:12:00 | 显示全部楼层
wowan1314 发表于 2014-4-9 11:47
好久没来了!
突然发现师兄发帖哦!
必须支持下!

随便写的

难得还有人记得我,这论坛一个月也上不了几次

应该有很多认识的或以前曾聊过的人

为什么显示的名字注册了就不能改了,导致我看不出各位的身份,应该很多是QQ好友吧
发表于 2014-4-9 12:16:35 | 显示全部楼层
caiqs 发表于 2014-4-9 12:12
随便写的

难得还有人记得我,这论坛一个月也上不了几次

我已经不是 “随便的人”了! 呵呵

现在基本不碰程序了,差不多快忘光了。

论坛很少来了。偶然无聊来看看,都没登陆! 今天看你发帖才登陆上来 支持下。

点评

哈哈,老葛可是为论坛做了大贡献的人!支持出山!  发表于 2014-4-9 13:13
又出山了?  发表于 2014-4-9 13:01
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2025-5-24 23:20 , Processed in 0.173083 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表