Path: utzoo!attcan!uunet!samsung!sdd.hp.com!wuarchive!mit-eddie!uw-beaver!cornell!wilk From: wilk@fife.cs.cornell.edu (Michael Wilk) Newsgroups: comp.lang.lisp Subject: Loop speeds Message-ID: <47103@cornell.UUCP> Date: 15 Oct 90 13:42:37 GMT Sender: nobody@cornell.UUCP Reply-To: wilk@cs.cornell.edu (Michael Wilk) Distribution: comp Organization: Cornell Univ. CS Dept, Ithaca NY Lines: 43 After puzzling over the results of the speed tests I performed on the "mirror" program, I discovered a disturbing discrepancy between the loop macro and the mapping functions. Consider the performance gap between running these two versions of function foo on a list of 30000 items: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (defun foo (x) (loop for item in x collect (atom item))) Elapsed Real Time = 7.86 seconds Total Run Time = 7.84 seconds User Run Time = 7.84 seconds System Run Time = 0.00 seconds Process Page Faults = 7 Dynamic Bytes Consed = 0 Ephemeral Bytes Consed = 240,176 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (defun foo (x) (mapcar #'atom x)) Elapsed Real Time = 0.14 seconds Total Run Time = 0.14 seconds User Run Time = 0.14 seconds System Run Time = 0.00 seconds Process Page Faults = 0 Dynamic Bytes Consed = 0 Ephemeral Bytes Consed = 240,008 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (These tests were run in Lucid Common Lisp on a DECstation 5000. The functions were compiled and optimized for speed. I ran the tests several times and chose the run with the fewest page faults. The predicate #'atom was chosen arbitrarily.) Would you conclude from this that one should always use mapcar instead of loop/for/collect in simple cases? Why isn't macro expansion smarter? -Michael Wilk (wilk@cs.cornell.edu)