3 ms·
CLISP doesn't compile functions input at the REPL or loaded from source files with LOAD. If you don't do (compile 'fib), you're testing AST interpretation, not
by kazinator 9y ago
CLISP doesn't compile functions input at the REPL or loaded from source files with LOAD. If you don't do (compile 'fib), you're testing AST interpretation, not byte code.
- tom_mellior 9y agoHa, excellent point. Thanks.
- tom_mellior 9y agoOK, so now we are ready to answer the great-great-grandparent's question: > Is SWI-Prolog really faster than CLisp? No. At least not on naive Fibonacci. [1]> (defun fib (n) (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))) FIB [2]> (compile 'fib) FIB ; NIL ; NIL [3]> (time (fib 38)) Real time: 6.730412 sec. Run time: 6.732 sec. Space: 0 Bytes 63245986 The project's GitHub page makes pretty much all the mistakes you can make when benchmarking: Comparing programs that are not equivalent and with wildly uncomparable optimization settings. There is an almost incomprehensible blurb at the end of https://github.com/TeamSPoon/wam_common_lisp https://github.com/TeamSPoon/wam_common_lisp that (I think) tries to argue that you should not turn on optimization in Lisp because it costs more than you gain. I disagree.
- zmonx 9y agoThank you for these benchmarks! For a fair comparison, one should however also take into account that SWI-Prolog is among the slower Prolog systems. I therefore recommend to also use a faster Prolog system. For example, I used the following Prolog translation of your code and ran it in GNU Prolog: n_fib(N0, F) :- ( N0 =< 1 -> F = 1 ; N1 is N0 - 1, N2 is N0 - 2, n_fib(N1, F1), n_fib(N2, F2), F is F1 + F2 ). On my machine configuration, GNU Prolog is more than thrice as fast as SWI-Prolog (even with -O) for: | ?- n_fib(38, F). F = 63245986 GNU Prolog in fact compiles to native code. You can test this by putting the code into a file, say fib.pl, and compiling it with the GNU Prolog compiler using: $ gplc fib.pl You can then run it with ./fib and invoke the above query.