Writing Emacs Primitives - Emacs に C の関数を追加する(2)

ちゃんと高速化されたことを確認しなければ。

以下、前回作った C による独自の emacs プリミティブ関数 onep と、 elisp で書いた onep-e 関数を、
10000回呼ぶテストを行っている。独自に作成したプリミティブ関数は、コンパイルされた新しい emacs 実行ファイルに組み込まれている。


(defun onep-e (n)
(= n 1))

(require 'cl)
cl
(defun test-1 ()
(loop repeat 10000 for x = (random 10)
if (onep x) collect x))

(defun test-2 ()
(loop repeat 10000 for x = (random 10)
if (onep-e x) collect x))

(require 'profile)
(setq profile-functions-list '(test-1 test-2))

M-x profile-functions
(loop repeat 1000
do
(test-1)
(test-2))

M-x profile-results

Function Calls Total time (sec) Avg time per call
====== ====== ================ =================
test-2 1000 12.907819 0.012908
test-1 1000 8.452284 0.008452

別の結果

Function Calls Total time (sec) Avg time per call
====== ====== ================ =================
test-2 1000 13.085885 0.013086
test-1 1000 8.633334 0.008633


素晴らしい成果。明らかに C で書いた test-1 の方が高速である。

良い Emacs ユーザーはお気に入りの Elisp を持つ。
間違った Emacs ユーザーはお気に入りの Emacs バイナリーを持つ。



現実逃避もいい加減にしないと、、