From: Juho S. <js...@ik...> - 2006-12-15 11:00:39
|
"Andreas Fredriksson" <dep...@gm...> writes: > Thank you, that is very interesting. I'm toying with something similar > here and seeing much less consing than what I did with arrays. There's > still _some_ consing, though. Do multiple-values-bind and values cons > in the general case or have I done something stupid, as in: > > (defun f (a b c) > (declare > (type single-float a b c)) > (values (+ a b) (- b a) (* c a))) > > (defun test () > (time > (dotimes (k 100000000) > (let ((i (coerce k 'single-float))) > (multiple-value-bind (x y z) (f i (+ i 10) (* i 20)) > (progn)))))) > > CL-USER> (test) > Evaluation took: > 3.328 seconds of real time > 3.328208 seconds of user run time > 0.0 seconds of system run time > 0 page faults and > 16,320 bytes consed. > > Why would this cons? Is it because my loop counter is becoming a large > enough fixnum that it has to be promoted to some arbitrary precision > integer? It shouldn't [*]. My guess is that the small amount of consing there is due to for example Slime doing something in another thread. [*] I assume you're on x86-64, where single-floats can be passed around as immediate values. On x86 or if using double-floats, you should declare F as inlined to avoid that consing a few gigabytes of temporary floats. -- Juho Snellman |