下面代码也可以做
 - (defun xd::list:del2 (l1 l2)
- (vl-remove-if '(lambda (x) (member x l1)) l2)
- )
测试下楼主的和上面的效率
 - (defun c:tt ()
- (setq b nil)
- (repeat 100 (setq b (cons (xdrx_math_rand 1 100) b)))
- (setq c nil)
- (repeat 100 (setq c (cons (xdrx_math_rand 1 100) c)))
- (xd::quickbench '((XD::List:del1 b c) (XD::List:del2 b c)))
- (princ)
- )
命令: TT
CPU:(1x)Intel(R) Core(TM) i7-4790 @ 3.60GHz 4Cores / Memory:16G / OS:WIN10企业版
Benchmarking ....... done for 4096 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
-------------------------------------------------------------------------------
(XD::LIST:DEL B C) 4096 1578 1578 2.89 <fastest>
(XD::LIST:DEL2 B C) 1024 1141 4564 1.00 <slowest>
-------------------------------------------------------------------------------
命令:
命令: TT
CPU:(1x)Intel(R) Core(TM) i7-4790 @ 3.60GHz 4Cores / Memory:16G / OS:WIN10企业版
Benchmarking ....... done for 4096 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
-------------------------------------------------------------------------------
(XD::LIST:DEL B C) 4096 1750 1750 3.00 <fastest>
(XD::LIST:DEL2 B C) 1024 1312 5248 1.00 <slowest>
-------------------------------------------------------------------------------
命令:
命令: tt
CPU:(1x)Intel(R) Core(TM) i7-4790 @ 3.60GHz 4Cores / Memory:16G / OS:WIN10企业版
Benchmarking ....... done for 2048 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
-------------------------------------------------------------------------------
(XD::LIST:DEL B C) 2048 1047 1047 2.89 <fastest>
(XD::LIST:DEL2 B C) 1024 1515 3030 1.00 <slowest>
-------------------------------------------------------------------------------
命令:
命令: (xd::list:del1 b c)
(41 21 59 65 73 57 52 50 1 3 50 81 1 65 50 81 78 72 72 1 41 44 11 41 73 20 72
57 44 1 65 1)
命令: tt
CPU:(1x)Intel(R) Core(TM) i7-4790 @ 3.60GHz 4Cores / Memory:16G / OS:WIN10企业版
Benchmarking ....... done for 4096 iterations. Sorted from fastest.
Statement Increment Time(ms) Normalize Relative
-------------------------------------------------------------------------------
(XD::LIST:DEL B C) 4096 1344 1344 3.16 <fastest>
(XD::LIST:DEL2 B C) 1024 1063 4252 1.00 <slowest>
-------------------------------------------------------------------------------
可见,楼主的代码效率要更高,所以尽量别用vl-remove-if
|