Subject: [clisp-list] Large performance decrease observed with timing loop

From: [email-masked] (Don Cohen)
Date: Sun Jun 9 17:48:02 2002

> Just posting some information about some large clisp slowdowns I have
 > observed simply by increasing a timing loop. The slowdowns are not
 > restricted to clisp (CMUCL performance decreases twice as fast as would
 > be expected with linear scaling).
That should be your first clue.

 > (defun merge-list-strings (&rest args)
 >   (let ((index 0) (element 0) (merged (first args)))
 >     (loop for index from 0 to (1- (length (first args))) do
 > 	  (dolist (element (rest args))
 > 	    (setf (nth index merged) (concatenate 'string (nth index merged) (nth index element)))))

A free hint, this last line has a lot to do with it.

 >     merged))

 > (time
 >   (loop for i from 1 to 1000 do
 >     (merge-list-strings '("abc" "123") '("def" "456") '("ghi" "789"))))
 > Space: 24115568 Bytes
Compare the space lines.  That's your next clue.

 > It's a bit too quick so I decide to boost the loop from 1000 to 10000
 > Space: 2401123568 Bytes

 > If the loop is increased to 20000 I would expect the code to take around
 > 120 seconds to complete. Instead it takes 484 seconds:
 > Space: 9602243568 Bytes

Note that the space is also a lot more than proportional to the number
of iterations.

---

From: Adam Warner <[email-masked]>
Date: Sun Jun 9 18:12:03 2002

> A free hint, this last line has a lot to do with it.

Thanks Don. My example kept generating longer lists every time:

(time
  (loop for i from 1 to 10 do
    (merge-list-strings '("abc" "123") '("def" "456") '("ghi" "789"))))

("abcdefghi" "123456789")("abcdefghidefghi"
"123456789456789")("abcdefghidefghidefghi"
"123456789456789456789")("abcdefghidefghidefghidefghi"
"123456789456789456789456789")("abcdefghidefghidefghidefghidefghi"
"123456789456789456789456789456789")
("abcdefghidefghidefghidefghidefghidefghi"
 "123456789456789456789456789456789456789")
("abcdefghidefghidefghidefghidefghidefghidefghi"
 "123456789456789456789456789456789456789456789")
("abcdefghidefghidefghidefghidefghidefghidefghidefghi"
 "123456789456789456789456789456789456789456789456789")
("abcdefghidefghidefghidefghidefghidefghidefghidefghidefghi"
 "123456789456789456789456789456789456789456789456789456789")
("abcdefghidefghidefghidefghidefghidefghidefghidefghidefghidefghi"
 "123456789456789456789456789456789456789456789456789456789456789")
Real time: 0.004203 sec.
Run time: 0.01 sec.
Space: 15540 Bytes

Please Dan and Pierpaolo consider telling me directly when I've done
something stupid. The thread deserved to end straight away when it
turned out my whole purpose for making the post was mistaken.

Regards,
Adam