Point 1 searchs the entire string for the first occurrence of character X. Each check compares the letter with between 1 and stringlength other letters. If a match is found, a check is made on each and every character in the string to see if it should be replaces. Total is 2 searches and 1 replace Point 2 simply removes the check but is still a comparison per character and a replace. Point 3 has no comparison (matches all) but the replace is not only a replace but also a ascii value shift (from lowercase ascii value to uppercase).
2 may be faster because while it is doing a search for the letter, it already knows what is being replaced. 3 has no initial search but the replace part has the shift. I'd still say 3 is faster though. -- Michael Dinowitz Lead Author - Adobe Coldfusion Anthology http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion On Wed, Aug 11, 2010 at 3:50 PM, Medic <[email protected]> wrote: > > True dat. What does your logic say about my three points? Which would be > fastest in your opinion? > > > On Wed, Aug 11, 2010 at 3:47 PM, Michael Dinowitz < > [email protected]> wrote: > >> >> Speed tests are always a false indicator of real work. I look at the 3 >> points and just apply logic. But test results always look good no >> matter. >> >> On Wed, Aug 11, 2010 at 11:55 AM, Medic <[email protected]> wrote: >> > >> > haha, yes we _all_ know that the regex will be much faster. I was just >> > wondering about the three points I made. >> > >> > On Wed, Aug 11, 2010 at 11:38 AM, Michael Dinowitz < >> > [email protected]> wrote: >> > >> >> >> >> The code that replaces each letter at a time will be much slower as it >> >> is looking through the entire string for a match for each letter. The >> >> RegEx isn't doing any real work for the pattern match as it is getting >> >> everything. The replace is also not a lot of work as it's just >> >> shifting everything within a certain range (lowercase) to a different >> >> range (uppercase). Ascii shift, basically. >> >> >> >> >> >> On Wed, Aug 11, 2010 at 11:30 AM, Medic <[email protected]> wrote: >> >> > >> >> > Haha. Now THAT is a nice waste of space. I like how you test for the >> >> > existence of the letter before you replace it. >> >> > >> >> > This actually makes me want to run speed tests on what would be >> faster: >> >> > >> >> > 1. testing for existence of lowercase letter - replacing lowercase >> with >> >> > uppercase using replace. >> >> > 2. not testing and just replacing the lowercase with the uppercase >> using >> >> > replace. >> >> > 3. just using replacenocase and replacing all letters with the >> uppercase >> >> > equiv. >> >> > >> >> > I bet if I showed this code to my boss he'd be like "whoa, that's >> deep." >> >> > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Order the Adobe Coldfusion Anthology now! http://www.amazon.com/Adobe-Coldfusion-Anthology-Michael-Dinowitz/dp/1430272155/?tag=houseoffusion Archive: http://www.houseoffusion.com/groups/cf-community/message.cfm/messageid:324678 Subscription: http://www.houseoffusion.com/groups/cf-community/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/groups/cf-community/unsubscribe.cfm
