(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秒 autolisp如果仅是表操作,也就是ARX的输入和输出,涉及到Autocad Object 就有很大区别了,不管是 repeat while mapcar 还是foreach都有自己的用途 学习了 感谢分享宝贵经验! 我也来一个效率研究心得
(setq TIME0 (getvar "millisecs"))
(SETQ i 0)
(REPEAT50000000
(if (not jb)(progn (setq jb (itoa i)) (setq i (1+ i))))
)
(setq hs (/ (- (getvar "millisecs") TIME0 0.0) 1000.0))
(print(strcat "有not耗时:"(vl-princ-to-string hs)))
;有一个not,执行效率低
(setq TIME0 (getvar "millisecs"))
(SETQ i 0)
(REPEAT50000000
(if jb ()(progn (setq jb (itoa i)) (setq i (1+ i))))
)
(setq hs (/ (- (getvar "millisecs") TIME0 0.0) 1000.0))
(print(strcat "无not耗时:"(vl-princ-to-string hs)))
;没有not,执行效率高,而且编译vlx后,估计不同,有待测试
再来一个效率研究心得(setq str
"甲1子2、3乙4丑5 6—7—8 9海0中-金=
丙Q寅W、E丁R卯T Y—U—I O炉P中[火]
\戊A辰S、D己F巳G H—J—K L大Z林X木C
V庚B午N、M辛,未. /—— 路旁土1
2壬3申4、5癸6酉7 8—9—0 -剑=锋A金S
D甲F戌G、H乙J亥K L—Z—X C山V头B火N
M丙,子.、/丁1丑2 3—4—5 6涧7下8水9
0戊-寅=、A己S卯D F—G—H J城K头L土Z
X庚C辰V、B辛N巳M ,—./—1 2白3蜡4金5
6壬7午8、9癸0未- =Q—W—E R杨T柳Y木U
I甲O申P、[乙]\酉A S—D—F G泉H中J水K
L丙Z戌X、C丁V亥B N—M—, .屋上1土2
3戊4子5、6己7丑8 9—0—- =霹Q雳W火E
R庚T寅Y、U辛I卯O P—[—] \松A柏S木D
F壬G辰H、J癸K巳L Z—X—C V长B流N水M
,甲.午/、乙1未2 3—4—5 6沙7中8金9
0丙-申=、丁Q酉W E—R—T Y山U下I火O
P戊[戌]、\A己S亥D F—G—H J平K地L木
庚Z子X、C辛V丑B N—M—, .壁/上1土2
3壬4寅5、6癸7卯8 9—0—- =金Q箔W金E
R甲T辰Y、U乙I巳O P—[—]\ 覆A灯S火D
F丙G午H、J丁K未L —— ZX天C河V水B
N戊M申,、.己/酉1 23—4—5 67大8驿9土0
-庚=戌Q、W辛E亥R T—Y—U I钗O钏P金A
S壬D子F、G癸H丑J K—L—Z X桑C柘V木B
N甲M寅,、.乙/卯1 2—3—4 5大6溪7水8
9丙0辰-=、Q丁W巳E R—T—Y U沙I中O土P
[戊]午]\、A己S未D F—G—H J天K上L火;
'庚ZX申C、V辛B酉N M—,—. /石12榴3木4
5壬6戌7、8癸9亥0 -—=—Q W大E海R水T"
)
(repeat 5 (setq str (strcat str str)))
(strlen str)
(setq TIME0 (getvar "millisecs"))
(repeat500000
(vl-string-position (ascii "/") str)
)
(strcat "vl-string-position耗时:"
(vl-princ-to-string
(setq hs (/ (- (getvar "millisecs") TIME0 0.0) 1000.0))
)
)
)
(setq TIME0 (getvar "millisecs"))
(repeat500000
(wcmatch str "[,*`/*,]")
)
(strcat "wcmatch耗时:"
(vl-princ-to-string
(setq hs (/ (- (getvar "millisecs") TIME0 0.0) 1000.0))
)
)
)
页:
1
[2]