【发布时间】:2014-04-14 13:03:45
【问题描述】:
在下面的程序中,删除该行
(declare (type (simple-array bit) arr))
使用 SBCL 使运行时间增加了 3 倍以上。另一方面,defclass 宏中通过:type 提供的类型信息似乎对性能没有影响。
(defclass class-1 () ((arr :type (simple-array bit))))
(defun sample (inst)
(declare (type class-1 inst))
(let ((arr (slot-value inst 'arr)))
(declare (type (simple-array bit) arr)) ;; 3x running time without
(map-into arr #'(lambda (dummy) (if (< (random 1.0) 0.5) 0 1)) arr)))
(let ((inst (make-instance 'class-1)))
(setf (slot-value inst 'arr) (make-array 10000 :element-type 'bit))
(loop for i from 1 to 10000 do (sample inst)))
如何在每次使用时不必将arr 插槽声明为simple-array bit 的情况下获得相同的性能优势?后者特别烦人,因为(据我所知)每次都需要通过let 或类似方式引入绑定;我不能只在需要的地方写(slot-value inst 'arr)。
【问题讨论】:
标签: performance common-lisp sbcl typing clos