字节编译函数的效率不如用 C 编写的原语函数, 但比用纯 Lisp 编写的版本快得多。下面是一个示例:
(defun silly-loop (n)
"Return the time, in seconds, to run N iterations of a loop."
(let ((t1 (float-time)))
(while (> (setq n (1- n)) 0))
(- (float-time) t1)))
⇒ silly-loop
(silly-loop 50000000) ⇒ 5.200886011123657
(byte-compile 'silly-loop)
⇒ [Compiled code not shown]
(silly-loop 50000000) ⇒ 0.6239290237426758
在此示例中,解释执行的代码需要 5 秒以上才能运行完毕, 而字节编译后的代码耗时不到 1 秒。 这些结果具有代表性,但实际数值可能有所不同。