[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: 1. warnings 2. optimizations
- To: <firstname.lastname@example.org>
- Subject: Re: 1. warnings 2. optimizations
- From: Bruno Haible <email@example.com>
- Date: Thu, 18 Sep 1997 22:59:08 +0200 (MET DST)
- >received: from halles.ilog.fr (halles.ilog.fr [172.16.1.96]) by ilog.ilog.fr (8.8.7/8.7.3) with ESMTP id WAA27436; Thu, 18 Sep 1997 22:59:09 +0200 (MET DST)
- In-reply-to: <9709188746.AA874609692@inet.stknhlg.com>
- References: <9709188746.AA874609692@inet.stknhlg.com>
> 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?
A better approach to the treatment of line numbers in CLISP would be
needed for this. But you can customize your ~/.emacs :
;; Meta-g :== Meta-x goto-line
(global-set-key "\M-g" 'goto-line)
> 2. The following 3 functions compute factorial:
> 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.
fac0 and fac2 are the same algorithm (they multiply the same numbers in the
same order), just in a different look.
> On a second thought... The reason must be that we get to the bignums
> faster with fac0 and fac2!
You are in the bignums nearly all the time (already after 15 multiplications
out of 10000). That cannot account for a 12% speedup. Think once more.
(Hint: In clisp, the time needed for the multiplication of a fixnum with
a bignum is proportional to the length (in bits) of the bignum and independent
of the smaller factor.)
You might then try these:
(defun fac3 (n)
(labels ((f (a b)
(case (- b a)
(2 (* (- b 1) b))
(3 (* (- b 2) (- b 1) b))
(4 (* (- b 3) (- b 2) (- b 1) b))
(t (let ((m (ash (+ a b) -1))) (* (f a m) (f m b))))
(if (plusp n) (f 0 n) 1)
(defun fac4 (n) (! n)) ; this is unfair