Lispworks append is too slow (2)
Hello all,The problem is that append is very slow in Lispworks and
I think that it is possible to write an efficient append
keeping the pointer of the "last cons". But, my code does
not work well, any clues how to write this efficient append?
Look at the code (it update two variables, thelist and the lastcons) :
(defstruct *ghost* )
(defmacro appendE (thelist lastcons element)
`(if (equal ,thelist nil) ; I am becoming a lisp programmer lol
(let () (setf ,lastcons (list (make-*ghost*))) (setf ,thelist (cons ,element ,lastcons)))
(if (typep ,lastcons '*ghost*)
(setf (car ,lastcons) ,element)
(let ((x (cons ,element nil))) (setf (cdr ,lastcons) x) (setf ,lastcons x))))
)
---------- Forwarded message ----------
From: Mauricio Toro <mauriciotorob@gmail.com>
Date: 25 avr. 2008 15:59
Subject: Lispworks append is too slow
To: lisp-hug@lispworks.com
Hello all,
Lispworks append is too slow..
Take a look at this code:
(defvar a (make-list 10000000))
(defvar b (make-list 10000000))
(defvar c )
(time (setf c (append a b)))
It's giving me this answer (and I compiled it)
User time = 3.468
System time = 0.091
Elapsed time = 4.027
Allocation = 120000096 bytes
Under SBCL it takes 0,001.
I was trying to rewrite this append, keeping the
last cons in a "pointer". But, it did not work.
Any clues?
Look at the code (it update two variables, thelist and the lastcons) :
(defstruct *ghost* )
(defmacro appendE (thelist lastcons element)
`(if (equal ,thelist nil) ; I am becoming a lisp programmer lol
(let () (setf ,lastcons (list (make-*ghost*))) (setf ,thelist (cons ,element ,lastcons)))
(if (typep ,lastcons '*ghost*)
(setf (car ,lastcons) ,element)
(let ((x (cons ,element nil))) (setf (cdr ,lastcons) x) (setf ,lastcons x))))
)
--
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas
Pontificia Universidad Javeriana, Colombia
Stagiare à l'Ircam
1, place Igor-Stravinsky 75004 Paris,
France de 2008 à 2009
--
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas
Pontificia Universidad Javeriana, Colombia
Stagiare à l'Ircam
1, place Igor-Stravinsky 75004 Paris,
France de 2008 à 2009