josephoswaldgg@hotmail.com <josephoswald@gmail.com> wrote:
+---------------
| > When running under cmucl, I get the following messages (repeatedly
| > with the memory size constantly increasing).
| > What am I doing wrong here? ...
|
| This is incredibly ugly and un-Lispy code. I'll try to point out a few
| major issues. [...[trimmed]...
+---------------
One additional issue is that the CMUCL interpreter tends to generate
quite a lot of garbage. You'll do a *lot* better if you compile your
code before you try to worry about the garbage-generation rate, e.g.:
cmu> (defun delay (n) (dotimes (i n)))
DELAY
cmu> (time (delay 1000000))
; Compiling LAMBDA NIL:
; Compiling Top-Level Form:
; [GC threshold exceeded with 12,013,880 bytes in use. Commencing GC.]
; [GC completed with 1,079,768 bytes retained and 10,934,112 bytes freed.]
; [GC will next occur when at least 13,079,768 bytes are in use.]
; [GC threshold exceeded with 13,090,712 bytes in use. Commencing GC.]
; [GC completed with 1,079,776 bytes retained and 12,010,936 bytes freed.]
; [GC will next occur when at least 13,079,776 bytes are in use.]
; [GC threshold exceeded with 13,089,240 bytes in use. Commencing GC.]
; [GC completed with 1,089,832 bytes retained and 11,999,408 bytes freed.]
; [GC will next occur when at least 13,089,832 bytes are in use.]
; [GC threshold exceeded with 13,099,296 bytes in use. Commencing GC.]
; [GC completed with 1,089,832 bytes retained and 12,009,464 bytes freed.]
; [GC will next occur when at least 13,089,832 bytes are in use.]
; Evaluation took:
; 4.03f0 seconds of real time
; 4.0f0 seconds of user run time
; 0.03f0 seconds of system run time
; 7,266,606,333 CPU cycles
; [Run times include 0.1f0 seconds GC run time]
; 133 page faults and
; 48,010,536 bytes consed.
;
NIL
cmu> (compile 'delay)
; Compiling LAMBDA (N):
; Compiling Top-Level Form:
DELAY
NIL
NIL
cmu> (time (delay 1000000))
; Compiling LAMBDA NIL:
; Compiling Top-Level Form:
; Evaluation took:
; 0.01f0 seconds of real time
; 0.01f0 seconds of user run time
; 0.0f0 seconds of system run time
; 26,082,042 CPU cycles
; 0 page faults and
; 0 bytes consed.
;
NIL
cmu>
Compare the number of "bytes consed" (total size of all objects
allocated by the GC during the execution of "time") in the two
of these: ~48 MB versus *zero*!
Also consider the runtime: ~4 seconds vs. 0.01.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607