Newbie: How to avoid allocation of locals ?
Posted: Sun Feb 21, 2010 7:14 pm
Hi,
I made test function to check behavior of Lisp for locals:
(defun strinc (str cnt)
(let ((lstr str))
(declare (integer cnt) (simple-base-string str) (simple-base-string lstr)
(optimize (speed 3) (safety 3) (debug 3) (compilation-speed 0) (space 0)))
(dotimes (i cnt)
(setf lstr (prin1-to-string (1+ (parse-integer lstr)))))
lstr))
Then I tested in OpenMCL:
? (time (strinc "1" 1000))
(STRINC "1" 1000) took 16 milliseconds (0.016 seconds) to run with 4 available CPU cores.
During that period, 15 milliseconds (0.015 seconds) were spent in user mode
0 milliseconds (0.000 seconds) were spent in system mode
40,136 bytes of memory allocated.
"1001"
? (time (strinc "1" 10000))
(STRINC "1" 10000) took 31 milliseconds (0.031 seconds) to run with 4 available CPU cores.
During that period, 32 milliseconds (0.032 seconds) were spent in user mode
0 milliseconds (0.000 seconds) were spent in system mode
472,208 bytes of memory allocated.
"10001"
I see, Lisp allocate a lot of memory for temporary variables. LispWorks & Allegro do the same.
Does any method exist to avoid reallocation ? Or any programming technics to minimize temporal allocations in Lisp ?
I made test function to check behavior of Lisp for locals:
(defun strinc (str cnt)
(let ((lstr str))
(declare (integer cnt) (simple-base-string str) (simple-base-string lstr)
(optimize (speed 3) (safety 3) (debug 3) (compilation-speed 0) (space 0)))
(dotimes (i cnt)
(setf lstr (prin1-to-string (1+ (parse-integer lstr)))))
lstr))
Then I tested in OpenMCL:
? (time (strinc "1" 1000))
(STRINC "1" 1000) took 16 milliseconds (0.016 seconds) to run with 4 available CPU cores.
During that period, 15 milliseconds (0.015 seconds) were spent in user mode
0 milliseconds (0.000 seconds) were spent in system mode
40,136 bytes of memory allocated.
"1001"
? (time (strinc "1" 10000))
(STRINC "1" 10000) took 31 milliseconds (0.031 seconds) to run with 4 available CPU cores.
During that period, 32 milliseconds (0.032 seconds) were spent in user mode
0 milliseconds (0.000 seconds) were spent in system mode
472,208 bytes of memory allocated.
"10001"
I see, Lisp allocate a lot of memory for temporary variables. LispWorks & Allegro do the same.
Does any method exist to avoid reallocation ? Or any programming technics to minimize temporal allocations in Lisp ?