From ... Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.freenet.de!newsfeed.r-kom.de!newsfeed.completel.de!news.netway.at!nmaster.kpnqwest.net!nnum.kpnqwest.net!EU.net!nreader2.kpnqwest.net.POSTED!not-for-mail Newsgroups: comp.lang.lisp Subject: Re: invert-string revisited References: Mail-Copies-To: never From: Erik Naggum Message-ID: <3231850263906024@naggum.net> Organization: Naggum Software, Oslo, Norway Lines: 109 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 31 May 2002 16:11:06 GMT X-Complaints-To: newsmaster@KPNQwest.no X-Trace: nreader2.kpnqwest.net 1022861466 193.71.199.50 (Fri, 31 May 2002 18:11:06 MET DST) NNTP-Posting-Date: Fri, 31 May 2002 18:11:06 MET DST Xref: archiver1.google.com comp.lang.lisp:34211 * Adam Warner | So it appears I've come up with a decent (and ridiculously simple) | algorithm for preserving original symbol case when converting symbols to | strings. Another decent and ridiculously simple way is to use the compiler. Timing interpreted code is generally considered quite silly. Before compilation of any function: (st1) ; cpu time (non-gc) 3,730 msec user, 40 msec system ; cpu time (gc) 400 msec user, 20 msec system ; cpu time (total) 4,130 msec user, 60 msec system ; real time 4,689 msec ; space allocation: ; 2,230,144 cons cells, 14,594,640 other bytes, 0 static bytes => nil (st2) ; cpu time (non-gc) 1,150 msec user, 0 msec system ; cpu time (gc) 120 msec user, 0 msec system ; cpu time (total) 1,270 msec user, 0 msec system ; real time 1,268 msec ; space allocation: ; 460,136 cons cells, 12,720,160 other bytes, 0 static bytes => nil After compilation of all functions: (st1) ; cpu time (non-gc) 20 msec user, 0 msec system ; cpu time (gc) 0 msec user, 0 msec system ; cpu time (total) 20 msec user, 0 msec system ; real time 19 msec ; space allocation: ; 0 cons cells, 240,000 other bytes, 0 static bytes => nil (st2) ; cpu time (non-gc) 30 msec user, 0 msec system ; cpu time (gc) 0 msec user, 0 msec system ; cpu time (total) 30 msec user, 0 msec system ; real time 39 msec ; space allocation: ; 0 cons cells, 720,000 other bytes, 0 static bytes => nil Test run on a 600 MHz Intel PIII with enough RAM and Allegro CL 6.2.beta. I am more impressed with the interpreted speed than anything else... Just for kicks, I ran the same tests with CMUCL 3.0.12 18d+ build 3350 (are these guys Microsoft employees or what?. Before compilation: * (st1) Compiling LAMBDA NIL: Compiling Top-Level Form: Evaluation took: 2.98 seconds of real time 2.87 seconds of user run time 0.01 seconds of system run time [Run times include 0.19 seconds GC run time] 447 page faults and 8699088 bytes consed. NIL * (st2) Compiling LAMBDA NIL: Compiling Top-Level Form: Evaluation took: 0.37 seconds of real time 0.37 seconds of user run time 0.0 seconds of system run time [Run times include 0.04 seconds GC run time] 0 page faults and 1351384 bytes consed. NIL After compilation: * (st1) Evaluation took: 0.0 seconds of real time 0.0 seconds of user run time 0.0 seconds of system run time 0 page faults and 155112 bytes consed. NIL * (st2) Evaluation took: 0.02 seconds of real time 0.02 seconds of user run time 0.0 seconds of system run time 0 page faults and 319488 bytes consed. NIL Please note that space is sometimes worth optimizing for. One simple test I could have done, with two additional states, is to test the character following a character with case to see if it is in the same case, to return the string unchanged if so. -- In a fight against something, the fight has value, victory has none. In a fight for something, the fight is a loss, victory merely relief. 70 percent of American adults do not understand the scientific process.