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

concatenate and merge



Hi folk,

I have wrote a transducer in MCL and it try to optimize it. I found that
the merge function conses much less that concatenate (1/3). On the other
hand it is a bit slower (4/3).

I wrote the following code :

(time 
(dotimes (i 10000)
  (merge 'string "abcdef" "hello" #'(lambda (y x) (declare (ignore x)) y)))
)

and
(time (dotimes (i 10000) (concatenate 'string "hello" "abcdef")))

which gives :

6 > 
(DOTIMES (I 10000) (MERGE 'STRING "abcdef" "hello" #'(LAMBDA (Y X) (DECLARE
(IGNORE X)) Y))) took 3173 milliseconds (3.173 seconds) to run.
Of that, 61 milliseconds (0.061 seconds) were spent in The Cooperative
Multitasking Experience.
 240000 bytes of memory allocated.
NIL
6 > 
(DOTIMES (I 10000) (CONCATENATE 'STRING "hello" "abcdef")) took 2153
milliseconds (2.153 seconds) to run.
Of that, 26 milliseconds (0.026 seconds) were spent in The Cooperative
Multitasking Experience.
322 milliseconds (0.322 seconds) was spent in GC.
 720000 bytes of memory allocated.
NIL
6 > 

Beside these considerations, I have one question : does it exist a better
function than merge or concatenate (both in space and time) ? Typically I
am doing the following struff a lot of time:

(method do-it ((self c) (s string))
        (setf (output-s self)  (concatenate 'string (output-s self)  s)))

---
Lafourcade Mathieu
GETA (Groupe d'Etude pour la Traduction Automatique)
IMAG (Institut de Mathematiques Appliquees de Grenoble)
BP 53 38041 GRENOBLE CEDEX 9, FRANCE
Tel : (33) 76 51 43 80          Fax : (33) 76 51 44 05

mathieu.lafourcade@imag.fr