Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news.harvard.edu!news2.near.net!MathWorks.Com!europa.eng.gtefsd.com!howland.reston.ans.net!vixen.cso.uiuc.edu!uchinews!att-out!nntpa!nntpa.cb.att.com!lgm
From: lgm@polaris.ih.att.com (Lawrence G. Mayka)
Subject: Re: Comparison: Beta - Lisp
In-Reply-To: haible@ma2s2.mathematik.uni-karlsruhe.de's message of 9 Sep 1994 16:37:49 GMT
Message-ID: <LGM.94Sep9182543@polaris.ih.att.com>
Sender: news@nntpa.cb.att.com (Netnews Administration)
Nntp-Posting-Host: polaris.ih.att.com
Organization: AT&T Bell Laboratories, Naperville, Illinois, USA
References: <34n2qe$d74@nz12.rz.uni-karlsruhe.de> <lenngrayCvunsr.448@netcom.com>
	<34q30t$n76@nz12.rz.uni-karlsruhe.de>
Date: Fri, 9 Sep 1994 23:25:42 GMT
Lines: 112

In article <34q30t$n76@nz12.rz.uni-karlsruhe.de> haible@ma2s2.mathematik.uni-karlsruhe.de (Bruno Haible) writes:

   Of course these numbers are right. Here is another set of figures, for
   the same integer array hacking benchmark:
	   C                                  7.7 sec
	   Lucid CL 3.0 production mode      47 sec
	   Lucid CL 3.0 development mode    226 sec
	   CLISP                            512 sec
   (All timings on a Sun Sparcstation IPC, this time.)

I added some type declarations (and removed some), in order to make
sure that no functions (at least, according to the disassembler) are
being called in the inner parts.  I've attached the resulting source
code.  (Note again that I am not asserting that =all= those type
declarations are necessary, only that I didn't want to take chances.)
The benchmark result on LispWorks 3.2, on an old Sparc LX, for

(fannkuch-fast 10)

is

57.3 sec

You didn't say what argument you passed to the function, by the way;
10 was as high as I was willing to go!

-----------------------------
(in-package :cl-user)

(defun fannkuch-fast (&optional (n (progn
                                     (format *query-io* "n = ?")
                                     (parse-integer (read-line *query-io*))
                                     )          )  )
  (declare (optimize (safety 0) (speed 3) (space 0) (debug 0)))
  (unless (and (> n 0) (<= n 100)) (return-from fannkuch-fast))
  (let ((n n))
    (declare (fixnum n))
    (let ((perm (make-array n :initial-element 0))
          (perm1 (make-array n :initial-element 0))
          (zaehl (make-array n :initial-element 0))
          (permmax (make-array n :initial-element 0))
          (bishmax -1))
      (declare (type simple-vector perm perm1 zaehl permmax))
      (declare (fixnum bishmax))
      (dotimes (i n)
        (declare (fixnum i))
        (setf (svref perm1 i) i))
      (prog ((\t n))
        (declare (fixnum \t))
        Kreuz
	(when (= \t 1) (go standardroutine))
	(setf (svref zaehl (the fixnum (1- \t))) \t)
	(setf \t (the fixnum (1- \t)))
	(go Kreuz)
        Dollar
	(when (= \t n) (go fertig))
	(let ((perm0 (svref perm1 0)))
	  (dotimes (i \t)
	    (declare (fixnum i))
	    (setf (svref perm1 i) (svref perm1 (the fixnum (1+ i)))))
	  (setf (svref perm1 \t) perm0)
          )
	(when (> (the fixnum
		      (setf (the fixnum (svref zaehl \t))
			    (the fixnum (1- (the fixnum (svref zaehl \t))))))
		 0)
	  (go Kreuz))
	(setf \t (the fixnum (1+ \t)))
	(go Dollar)
        standardroutine
	(dotimes (i n)
	  (declare (fixnum i))
	  (setf (svref perm i) (svref perm1 i)))
	(let ((Spiegelungsanzahl 0) (k 0))
	  (declare (fixnum Spiegelungsanzahl k))
	  (loop
	   (when (= (the fixnum (setq k (svref perm 0))) 0) (return))
	   (let ((k2 (ash (the fixnum (1+ k)) -1)))
	     (declare (fixnum k2))
	     (dotimes (i k2)
	       (declare (fixnum i))
	       (rotatef (svref perm i) (svref perm (the fixnum (- k i)))))
	     )
	   (setf Spiegelungsanzahl (the fixnum (1+ Spiegelungsanzahl)))
	   )
	  (when (> Spiegelungsanzahl bishmax)
	    (setq bishmax Spiegelungsanzahl)
	    (dotimes (i n)
	      (declare (fixnum i))
	      (setf (svref permmax i) (svref perm1 i)))
            ) )
	(go Dollar)
        fertig
        )
      (format t "The maximum was ~D.~% at " bishmax)
      (format t "(")
      (dotimes (i n)
        (declare (fixnum i))
        (when (> i 0) (format t " "))
        (format t "~D" (the fixnum (1+ (the fixnum (svref permmax i)))))
        )
      (format t ")")
      (terpri)
      (values)
      ) ) )
--------------------------------
--
        Lawrence G. Mayka
        AT&T Bell Laboratories
        lgm@ieain.att.com

Standard disclaimer.
