Re: When does ADJUST-ARRAY cons?



On Mon, 18 Jul 2005 16:00:29 +0200, Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx> wrote:

> Perhaps you should choose a better implementation?

Did it occur to you that these timings might be affected by other
factors like hardware or the underlying OS?

If you insist, on my machine CLISP (2.33.2) needs more than twice as
long as LispWorks for the same file. So, by your childish measure of
"better" LispWorks is twice as good as CLISP, right?

Cheers,
Edi.



edi@miles:/tmp$ wc test.big
1644906 6266610 64931058 test.big
edi@miles:/tmp$ cat foo.lisp
(defconstant +max-buflen+ 102400) ; make larger later, if that helps
(defparameter *buffer* (make-array +max-buflen+ :element-type 'base-char))

(defparameter *pos* 0)
(defparameter *line* nil)
(defconstant +base-line-length+ 120)
(defparameter *base-line* (make-array 0
:element-type 'base-char
:adjustable t
:displaced-to *buffer*
:displaced-index-offset 0))

(defun load-line-2 (strm)
(flet ((reset ()
(setf *pos* 0)
(unless (plusp (read-sequence *buffer* strm))
(error 'end-of-file))))
(let ((pos (position #\Newline *base-line*)))
(when (or (null pos)
(zerop pos)
(> (incf *pos* (1+ pos)) +max-buflen+))
(reset))
(when (>= (+ +base-line-length+ *pos*)
+max-buflen+)
(reset))
(setq *line* (adjust-array *base-line* +base-line-length+
:element-type 'base-char
:displaced-to *buffer*
:displaced-index-offset *pos*)))))

(defun foo ()
(with-open-file (strm "/tmp/test.big")
(ignore-errors
(dotimes (i 1000000)
(load-line-2 strm)))))
edi@miles:/tmp$ clisp -E "ISO-8859-1"
i i i i i i i ooooo o ooooooo ooooo ooooo
I I I I I I I 8 8 8 8 8 o 8 8
I \ `+' / I 8 8 8 8 8 8
\ `-+-' / 8 8 8 ooooo 8oooo
`-__|__-' 8 8 8 8 8
| 8 o 8 8 o 8 8
------+------ ooooo 8oooooo ooo8ooo ooooo 8

Copyright (c) Bruno Haible, Michael Stoll 1992, 1993
Copyright (c) Bruno Haible, Marcus Daniels 1994-1997
Copyright (c) Bruno Haible, Pierpaolo Bernardi, Sam Steingold 1998
Copyright (c) Bruno Haible, Sam Steingold 1999-2000
Copyright (c) Sam Steingold, Bruno Haible 2001-2004


[1]> (load (compile-file "foo.lisp"))

Compiling file /tmp/foo.lisp ...

Wrote file /tmp/foo.fas
0 errors, 0 warnings
;; Loading file /tmp/foo.fas ...
;; Loaded file /tmp/foo.fas
T
[2]> (time (foo))

Real time: 6.352963 sec.
Run time: 6.353035 sec.
Space: 23160048 Bytes
GC: 45, GC time: 0.046994 sec.
NIL ;
#<END-OF-FILE #x203FB2FE>
[3]> (quit)
Bye.
edi@miles:/tmp$ lw
LispWorks(R): The Common Lisp Programming Environment
Copyright (C) 1987-2005 LispWorks Ltd. All rights reserved.
Version 4.4.5
Saved by edi as lw-console, at 26 Apr 2005 11:21
User edi on miles
; Loading text file /usr/local/lib/LispWorks/lib/4-4-0-0/config/siteinit.lisp
; Loading text file /usr/local/lib/LispWorks/lib/4-4-0-0/private-patches/load.lisp
; Loading text file /home/edi/.lispworks

CL-USER 1 > (load (compile-file "foo.lisp"))
;;; Compiling file foo.lisp ...
;;; Safety = 3, Speed = 1, Space = 1, Float = 1, Interruptible = 0
;;; Compilation speed = 1, Debug = 2, Fixnum safety = 3
;;; Source level debugging is on
;;; Source file recording is on
;;; Cross referencing is on
; (TOP-LEVEL-FORM 1)
; (DEFCONSTANT +MAX-BUFLEN+)
; (DEFPARAMETER *BUFFER*)
; (DEFPARAMETER *POS*)
; (DEFPARAMETER *LINE*)
; (DEFCONSTANT +BASE-LINE-LENGTH+)
; (DEFPARAMETER *BASE-LINE*)
; LOAD-LINE-2
; FOO
; (TOP-LEVEL-FORM 2)
; Loading fasl file /tmp/foo.ufsl
#P"/tmp/foo.ufsl"

CL-USER 2 > (time (foo))
Timing the evaluation of (FOO)
; Loading fasl file /usr/local/lib/LispWorks/lib/4-4-0-0/load-on-demand/pcl/util/callcoun.ufsl

user time = 2.552
system time = 0.037
Elapsed time = 0:00:03
Allocation = 124448 bytes standard / 10413535 bytes conses
0 Page faults
NIL
#<END-OF-FILE 206EBF3C>

--

Lisp is not dead, it just smells funny.

Real email: (replace (subseq "spamtrap@xxxxxxxxxx" 5) "edi")
.



Relevant Pages

  • Re: 3n+1 problem
    ... LispWorks: 0.59 seconds ... It's easy to get the LW timings dramatically down by using the fixnum- ... safety declaration: ...   (loop for i from from to to ...
    (comp.lang.lisp)
  • Re: 3n+1 problem
    ... LispWorks: 0.59 seconds ... It's easy to get the LW timings dramatically down by using the fixnum- ... (fixnum from to)) ... (loop for i from from to to ...
    (comp.lang.lisp)