LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 1998)Back to main REXXLIST pageJoin or leave REXXLIST (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 21 Aug 1998 02:27:02 +0200
Reply-To:     REXX Programming discussion list <REXXLIST@UGA.CC.UGA.EDU>
Sender:       REXX Programming discussion list <REXXLIST@UGA.CC.UGA.EDU>
From:         Vidar Tysse <Fake_See_sig@NOSPAMPLEASE.COM>
Organization: VT Systemutvikling AS
Subject:      Re: A REPLACE( ) function

Chris Barnabo <irish89@ibm.net> wrote in message vevfuvozarg.ey04oh0.pminews@news3.ibm.net... >On Thu, 20 Aug 1998 09:41:38 -0500, doug@hotrocks.msfc.nasa.gov wrote: >>Thank you all. Hopefully the OS/2 version of REXX will get the ANSI >>CHANGESTR() routine at some point. >> >>Out of curiousity I did a quick little time test on the two routines >>posted. For a thousand iterations (units are seconds): >> >>0.240000 - By Mike Cowlishaw >>0.470000 - By Michael Motek & Chris Barnabo >>0.430000 - By Michael Motek & Chris Barnabo without the internal 'If >>Length(R) > 0 Then ... ' > >Interesting! Usually I've found parse to be slower than other functions >for breaking a string down, but I'll bet Mike C's use of concatenation is >faster than the insert() that Mike M. and I had in our function (Mike M, by >the way, good catch and improvement on my version!) > I read a piece on recursion the other day, and I thought it might be applied to this problem. This is what I came up with, based on Mike Cowlishaw's CHANGE routine:

/* Vidar Tysse's recursive VTCHANGE(haystack,needle,newneedle) */ vtChange: procedure parse arg string, old, new if old='' then return new||string parse var string prefix (old) string if string=='' then return prefix return prefix||new||vtChange(string,old,new)

It's shorter than Chris/Mike M's REPLACE(), and it runs a little quicker, according to tests that I have done with Regina REXX. The only problem is call stack overflow, I guess. The following is a typical output of a test program I wrote. Let me know if you want me to post the test REXX as well - it's a bit lengthy. ------------------ Changing " a" to " another" in "Mary had a little lamb, and the doctor fainted." for 10000 iterations: [..some output removed..] ...and here are the results of the WIN32 REXX-Regina_0_08d 4.75 26 Mar 1998 jury: ChangeStr()...: 0.00008910 sec/call, i.e. 1.00 times slower than the BIF Change()......: 0.00020730 sec/call, i.e. 2.33 times slower than the BIF Replace().....: 0.00032440 sec/call, i.e. 3.64 times slower than the BIF vtChange()....: 0.00027440 sec/call, i.e. 3.08 times slower than the BIF ------------------

Since the test above only changes 2 occurrences, I ran the following test, which changes 89 occurrences, and thus is a better comparison of the routines: ------------------ Changing "a" to "another" in "Mary had a little lamb, and the doctor fainted. More aaaaaaaaaaaaaaaas added aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/ aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa/aa." for 10000 iterations: [..some output removed..] ChangeStr()...: 0.00011820 sec/call, i.e. 1.00 times slower than the BIF Change()......: 0.00187370 sec/call, i.e. 15.85 times slower than the BIF Replace().....: 0.01126920 sec/call, i.e. 95.34 times slower than the BIF vtChange()....: 0.00783830 sec/call, i.e. 66.31 times slower than the BIF ------------------

Mike Cowlishaw's CHANGE() is impressive - always a lot faster than the two others, and only from 2 to 16 times slower than the CHANGESTR() BIF in most cases. An exception is the case where both old and new strings are 1 character in length (e.g. replace all 'a' with 'b'), where ChangeStr() really flies.

-- Vidar Tysse - aka "vtsystem AT bgnett DOT no"


Back to: Top of message | Previous page | Main REXXLIST page