明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: 鱼与熊掌

[经验] 大数据时代.代码不快就崩溃.关于Lisp执行效率探究

[复制链接]
发表于 2015-6-11 11:44 | 显示全部楼层
  1. ;计时器开始******************
  2. (defun cx-jsq ()
  3.   (setq time_tmp (getvar "TDUSRTIMER"))
  4. )
  5. (defun cx-end-jsq ()
  6.   (setq        time_tmp (- (getvar "TDUSRTIMER") time_tmp)
  7.                 time_tmp (* time_tmp 86400)
  8.   )
  9.   (prompt (strcat "用时" (rtos time_tmp 2 4) "秒"))
  10.   (setq time_tmp nil)
  11.   (princ)
  12. )
  13. ;准备测试数据
  14. (defun c:tx1()
  15.         (cx-jsq)
  16.         (setq all_lst1 nil)
  17.         (setq lst '((1 "a") (2 "b") (3 "c")))
  18.         (repeat 100000 ;10w个原子
  19.           (setq all_lst1(cons lst all_lst1))
  20.         )
  21.         (cx-end-jsq)
  22.   (princ)
  23. )
  24. ;开始测试,都让他们删除掉“0”开头的数据
  25. ;mapcar
  26. (defun c:tt1()
  27.         (cx-jsq)
  28.         (setq all_lst all_lst1)
  29.         (setq lstx1 nil)
  30.         (mapcar '(lambda(x) (if(= 1 (car x)) (setq lstx1 (cons x lstx1))))all_lst)
  31.   (cx-end-jsq)
  32.   (princ)
  33. )
  34. ;l-remove-if-not
  35. (defun c:tt2()
  36.         (cx-jsq)
  37.         (setq all_lst all_lst1)
  38.         (setq lstx2 nil)
  39.         (setq lstx2(vl-remove-if-not '(lambda(x) (= 1 (car x))) all_lst))
  40.   (cx-end-jsq)
  41.   (princ)
  42. )
  43. ;repeat
  44. (defun c:tt3()
  45.         (cx-jsq)
  46.         (setq all_lst all_lst1)
  47.         (setq lstx3 nil)
  48.         (setq n (length all_lst))
  49.         (repeat n
  50.                 (setq x (car all_lst))
  51.                 (if(= 1(car x)) (setq lstx3 (cons x lstx3)))
  52.                 (setq all_lst (cdr all_lst))
  53.         )
  54.   (cx-end-jsq)
  55.   (princ)
  56. )
  57. ;while
  58. (defun c:tt4()
  59.         (cx-jsq)
  60.         (setq all_lst all_lst1)
  61.         (setq lstx4 nil)
  62.         (setq n (length all_lst))
  63.         (while (setq x (car all_lst))
  64.                 (if(= 1(car x)) (setq lstx4 (cons x lstx4)))
  65.                 (setq all_lst (cdr all_lst))
  66.         )
  67.   (cx-end-jsq)
  68.   (princ)
  69. )
  70. ;foreach
  71. (defun c:tt5()
  72.         (cx-jsq)
  73.         (setq all_lst all_lst1)
  74.         (setq lstx4 nil)
  75.         (setq n (length all_lst))
  76.         (foreach x all_lst
  77.                 (if(= 1(car x)) (setq lstx5 (cons x lstx5)))
  78.         )
  79.   (cx-end-jsq)
  80.   (princ)
  81. )
第一遍测试
命令: 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秒
发表于 2015-6-11 13:01 来自手机 | 显示全部楼层
autolisp如果仅是表操作,也就是ARX的输入和输出,涉及到Autocad Object 就有很大区别了,不管是 repeat while mapcar 还是foreach都有自己的用途
发表于 2015-6-19 22:11 | 显示全部楼层
学习了     
发表于 2021-9-29 17:42 | 显示全部楼层
感谢分享宝贵经验!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-28 01:57 , Processed in 0.254866 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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