Advertisement
logicmoo

WAM-CL, 3x slower SBCL, 17x faster than CLISP, potentually

Oct 21st, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Prolog 1.65 KB | None | 0 0
  1. /*
  2.  
  3. NOTES:
  4.  
  5. * WAM-CL currently produces code 6 times slower than the handwritten code
  6.  
  7. * Handwritten Prolog is 2-3 slower than SBCL
  8.  
  9. * If WAM-CL becomes fast as handwritten code,
  10. ** it will be 17 times faster than CLISP
  11. ** it will be 6 times faster than ECL
  12.  
  13.  
  14.  
  15.  
  16. (defun fib (n)
  17.   (if (> n 1)
  18.     (+ (fib (- n 1))
  19.        (fib (- n 2)))
  20.     1))
  21.  
  22. */
  23.  
  24. % WAM-CL
  25. fibc(A, K) :- !,
  26.         B=[[bv(n, [A|_])]],
  27.         sym_arg_val_envc(n, A, C, B),
  28.         >(C, 1, D),
  29.         (   D\=[]
  30.         ->  sym_arg_val_envc(n, A, E, B),
  31.             -(E, 1, F),
  32.             fibc(F, I),
  33.             sym_arg_val_envc(n, A, G, B),
  34.             -(G, 2, H),
  35.             fibc(H, J),
  36.             +(I, J, L),
  37.             K=L
  38.         ;   K=1
  39.         ).
  40. fibc(_, _) :- '<<=='(fibc(n),if(n>1, fibc(n-1)+fibc(n-2), 1)).
  41.  
  42.  
  43. % HANDWRITTEN
  44.  
  45. fibp2(N, F) :-
  46.         N =< 1
  47.         -> F = 1
  48.         ;
  49.         N1 is N-1,
  50.         N2 is N-2,
  51.         fibp2(N1, F1),
  52.         fibp2(N2, F2),
  53.         F is F1+F2.
  54.  
  55.  
  56.  
  57.  
  58.  
  59. % SBCL 1.3.1
  60. % * (time (fib 38))
  61. % 1.264000 seconds of total run time (1.264000 user, 0.000000 system)
  62.  
  63. % YAP-Prolog (Hand written)
  64. % ?- time(fibp2(38,O)).
  65. % 3.124 CPU in 3.148 seconds ( 99% CPU)
  66.  
  67. % YAP-Lisp (WAM-CL)
  68. % ?- time(fibc(38,O)).
  69. % 20.184 CPU in 20.340 seconds ( 99% CPU)
  70.  
  71. % SWI-Prolog (Hand written)
  72. % ?- timel(fibp2(38,O)).
  73. % 24.558 CPU in 24.826 seconds (99% CPU, 18027611 Lips)
  74.  
  75. % ECL 15.3.7
  76. % > (time (fib 38))
  77. % run time  : 25.516 secs (real time : 26.290 secs)
  78.  
  79. % CLISP 2.49
  80. % (time (fib 38))
  81. % 53.0 sec.
  82.  
  83. % SWI-Lisp (WAM-CL)
  84. % ?- time(fibc(38,O)).
  85. % 113.043 CPU in 114.324 seconds (99% CPU, 15665558 Lips)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement