はじめに
destructuring-bind
とlet
で速度比較をしました。
ソースコード
(defmacro with-bench ((&optional (num-repeat 10000000))
&body body)
`(time (loop repeat ,num-repeat do (progn ,@body))))
(defun dbind-test ()
(let ((list (list 1 2 3)))
(with-bench ()
(destructuring-bind (x y z) list
(+ x y z)))))
(defun let-test ()
(let ((list (list 1 2 3)))
(with-bench ()
(let ((x (first list))
(y (second list))
(z (third list)))
(+ x y z)))))
結果
-
dbind-test
: 約3.9秒 -
let-test
: 約0.12秒
CL-USER> (dbind-test)
Evaluation took:
3.899 seconds of real time
3.863381 seconds of total run time (3.829654 user, 0.033727 system)
99.08% CPU
9,716,958,684 processor cycles
4,016 bytes consed
NIL
CL-USER> (dbind-test)
Evaluation took:
3.914 seconds of real time
3.878260 seconds of total run time (3.841974 user, 0.036286 system)
99.08% CPU
9,751,604,518 processor cycles
33,072 bytes consed
NIL
CL-USER> (dbind-test)
Evaluation took:
3.864 seconds of real time
3.827455 seconds of total run time (3.792557 user, 0.034898 system)
99.04% CPU
9,629,652,079 processor cycles
32,768 bytes consed
NIL
CL-USER> (let-test)
Evaluation took:
0.125 seconds of real time
0.108741 seconds of total run time (0.107721 user, 0.001020 system)
87.20% CPU
311,094,075 processor cycles
0 bytes consed
NIL
CL-USER> (let-test)
Evaluation took:
0.122 seconds of real time
0.105200 seconds of total run time (0.103102 user, 0.002098 system)
86.07% CPU
304,988,627 processor cycles
0 bytes consed
NIL
CL-USER> (let-test)
Evaluation took:
0.118 seconds of real time
0.100798 seconds of total run time (0.100035 user, 0.000763 system)
85.59% CPU
293,909,444 processor cycles
0 bytes consed
NIL