[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

1. warnings 2. optimizations



     1. Emacs compile buffer doesn't understand the CLISP warnings (they 
     are not in the standard format like "file:line:message"). Is it 
     possible to make CLISP compilation message more standard?
     
     2. The following 3 functions compute factorial:
     
     (defun fac0 (n)
       "Compute the factorial. (Tail-recurcive algorithm)."
       (declare (type (integer 0 *) n))
       (labels ((f (a b) (if (plusp b) (f (* a b) (1- b)) a))) (f 1 n)))
     
     (defun fac2 (n)
       "Compute the factorial. (Iterative algorithm)."
       (declare (type (integer 0 *) n))
       (do ((i n (1- i)) (r 1)) ((zerop i) r) (setq r (* r i))))
     
     (defun fac1 (n)
       "Compute the factorial. (Iterative algorithm)."
       (declare (type (integer 0 *) n))
       (do ((i 1 (1+ i)) (r 1)) ((= i n) (* r i)) (setq r (* r i))))
     
     > (time (progn (fac0 10000) nil))
     
     Real time: 9.583 sec.
     Run time: 9.163176 sec.
     Space: 78649300 Bytes
     GC: 97, GC time: 6.5894752 sec.
     nil
     > (time (progn (fac1 10000) nil))
     
     Real time: 8.162 sec.
     Run time: 8.0816208 sec.
     Space: 69640472 Bytes
     GC: 86, GC time: 5.808352 sec.
     nil
     > (time (progn (fac2 10000) nil))
     
     Real time: 9.284 sec.
     Run time: 9.2032336 sec.
     Space: 78649300 Bytes
     GC: 98, GC time: 6.6695904 sec.
     nil
     
     I would expect more difference between fac0 and (fac1 and fac2) than  
     between fac1 and fac2. And I definitely did not expect much difference 
     between fac 1 and fac2.
     
     On a second thought... The reason must be that we get to the bignums 
     faster with fac0 and fac2! (obviously the slow-down is because of more 
     gc)
     
     Any comments?