On Aug 2, 2005, at 1:45 AM, Andrew Krespanis wrote:

On 8/2/05, Ben Curtis <[EMAIL PROTECTED]> wrote:


Good catch. Now we're talking a good excuse for regular expressions.
Instead of my recommendation of:

     a[i].getAttribute('href').toUpperCase().indexOf("HTTP://") == 0

...I now recommend:

     /^https?:\/\//i.test(a[i].getAttribute('href'))



Talk about technology for technology's sake! At least you admitted it
("good _excuse_ for regular expressions" ;)

RegExp() is one of the top three resource hungry javascript functions
to avoid. The other two biggies being eval( ) and setInterval. ( JS
Gurus: please feel free to correct me on that one if you believe
otherwise! )

This is outdated information, apparently. I had heard the same, and was curious if things had changed since then, so I ran tests. In Firefox, the regular expression is faster than the complete indexOf, and just as fast as your minimal indexOf check. Not so in Windows IE 5.5, and in Win IE 6 the two techniques are on par. This would indicate a common audience sees no difference or a performance improvement with regular expressions over indexOf.

http://www.bivia.com/sandbox/code_performance/ string_parse_speed_test.html

The difference in speed is minor enough (fractions of milliseconds) that the extra code to make the indexOf check the same factors (i.e., case insensitivity, that "://" isn't occurring somewhere later in the url, after the protocol, etc.) is a factor (about 60 bytes = 0.4 milliseconds over 1Mbps broadband, or twenty times the speed of the regexp execution).

But, honestly -- fractions of a millisecond. The only concerns I have for the equation are: 1- if it's unobtrusively applied, then is it bullet proof (that is, can it give a false positive a non-scriptor will have to contend with)? 2- is it easy to read, understand, and modify three years later without documentation?

--

    Ben Curtis : webwright
    bivia : a personal web studio
    http://www.bivia.com
    v: (818) 507-6613




******************************************************
The discussion list for  http://webstandardsgroup.org/

See http://webstandardsgroup.org/mail/guidelines.cfm
for some hints on posting to the list & getting help
******************************************************

Reply via email to