Javascript performance - IE 5.5 vs IE 5.0...known issues?

bdonalds
bdonalds used Ask the Experts™
on
I am creating a form than has many many many fields.  To make it easy on the user, I have created a function which the user can call that "fills down" values and selections automatically, since many of the fields may contain the same information.  It works, but it is excruciatingly slow when I tested it on my machine, running IE 5.5.  I tested on IE 5.0, and it was MUCH faster, probably at least by a factor of 50.  Are there any known issues between the two versions?

I'll save you the bandwidth of posting my code unless requested...it's a lot.  Here are some examples of what JS is doing to the form:

if (document.form[field].checked) {
  document.form[other_field].checked=true;
} else {
  document.form[other_field].checked=false;
}
======
document.form[field].value=document.form[other_field].value
======
if (document.all[division].style.visibility=='visible') {
  document.all[other_division].style.visibility='visible';    
} else {
  document.all[other_division].style.visibility='hidden';
}
======
document.form[field].selectedIndex=document.form[other_field].selectedIndex
======

Each of the above type actions are called several times within for loops.  I have declared an array for the dynamic variable that plug into the "division" and "field" objects above, so I am not declaring variables within each iteration of the loop.

Anyway, I put some code that spits out the time for each block of code, and in 5.0, the times range from 0 to 30ms.  In IE 5.5, the times range from 60 to over 140ms.

thanks,

Bryan
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
rather than IF statements, try this:

if (document.form[field].checked) {
 document.form[other_field].checked=true;
} else {
 document.form[other_field].checked=false;
}

becomes :

document.form[other_field].checked =  (document.form[field].checked);

 And

if (document.all[division].style.visibility=='visible') {
 document.all[other_division].style.visibility='visible';    
} else {
 document.all[other_division].style.visibility='hidden';
}

becomes :

document.all[other_division].style.visibility = document.all[division].style.visibility;

*********************************************************

It may not help, but it will cut down the amount of code. Plus, it seems to me as though document.form[] will return the form, not the element. If you want the element of the form you should be doing document.formName.elements[division];

Unless you named your form "form" like so:

<form name="form>

Which is a BAD thing. Name it ANYTHING but "form"

Author

Commented:
Sorry, the name "form" was just meant to be generic, not what I actually named the form.

I did get rid of my pointless if statements (so ridiculously obvious now that you showed me...kicking myself), but it didn't solve the problem.  The performance numbers were the same.  

This problem may be something specific to this environment, since all of my "googleing" has turned up nothing in regard to a version specific javascript performance issue with IE.  Our standard install is IE version 5.50.4522.1800CO (SP1).

In the example I am testing, I am comparing/updating the states/values of about 75-100 fields.  It is taking about 20-35 seconds to complete.  There is definitely something wrong here, and it may not be code related.  ...Regardless of how sloppy or amateurly I am coding...

thanks,

Bryan
Interesting. Can you send me a link to the page that I can go to? I'd like to see it running for myself. Maybe I'll see something to optimize.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Maybe I can clarify...

Here is an example of the "real" code:

document.all[var_array[i][j]['div_thresh']].style.visibility=document.all[var_array[0][j]['div_thresh']].style.visibility;

var_array[][][] is a three dimensional array, where I stored the names of the <div> ids.  This line of code sits in two nested for loops, as i and j go from 0 to a number specified in a previous form (i went to 4, and j to 5 in the test I ran).

This particular line of code alone is taking an an average of 110ms to execute on my machine with IE 5.5.  When I do it on another machine, with IE 5.0, it's coming back in 0-15ms.  I then tried it on a different machine with IE 5.5, and got the same 110ms result.  

The two machines with IE 5.5 are the same standard build here at work, and the IE 5.0 machine is different.  I wanted to ascertain if there was a known issue between the two versions before I headed to the lab and ran more tests on different machines.

thanks,

Bryan
what are you using to determine the execution time for this? (out of curiosity).

Also out of curiosity, try this page in both browsers:

http://w3.one.net/~jwclymer/bench.html

Author

Commented:
TallerMike-

I can't give you a link to the page.  It's on our private network, and I don't have a public server set up to run the app.  I will send you the source code though.

thanks!

Bryan

Author

Commented:
TallerMike-

I can't give you a link to the page.  It's on our private network, and I don't have a public server set up to run the app.  I will send you the source code though.

thanks!

Bryan
results from IE browser:

step 1, interface: 1 metric: 0 time:0
step 2, interface: 1 metric: 0 time:0
step 3, interface: 1 metric: 0 time:0
step 4, interface: 1 metric: 0 time:50
step 5, interface: 1 metric: 0 time:0
step 6, interface: 1 metric: 0 time:0
step 1, interface: 1 metric: 1 time:0
step 2, interface: 1 metric: 1 time:60
step 3, interface: 1 metric: 1 time:0
step 4, interface: 1 metric: 1 time:0
step 5, interface: 1 metric: 1 time:50

I'm running:

5.50.4134.0100

Author

Commented:
Oh!  Forgot about the benchmark results:

My machine
IE 5.5:  1490 loops/ms
Opera 6.0:  99 loops/ms (yikes!)
Mozilla 1.0:  1409 loops/ms

Other machine
IE 5.0:  2558 loops/ms

Not too scientific, since it is on two different machines, but....

Bryan

Author

Commented:
Oh!  Forgot about the benchmark results:

My machine
IE 5.5:  1490 loops/ms
Opera 6.0:  99 loops/ms (yikes!)
Mozilla 1.0:  1409 loops/ms

Other machine
IE 5.0:  2558 loops/ms

Not too scientific, since it is on two different machines, but....

Bryan

Author

Commented:
Mike-

Thanks for your assistance.  It looks like it's a problem with the standard install of IE here.  With any luck, I should be able to get that fixed in 20-30 years!! :)

thanks,

Bryan
That's pretty funny. Glad I could be of assitance.

I only got 1200 out of it... but then again I'm doing a billions things at once.

Author

Commented:
As it turns out, it appears that the problem might be something else...  I have created a page that tests the speed of several javascript functions.  It is slower than molasses on my PC, and a guy near me, but others don't see the same problems.  

So, not a javascript or browser problem, it appears!
Maybe you should look for a PC benchmark download to test your computer for memory problems... What OS are you running?

Author

Commented:
It's a weird thing.  I stole and modified the code from Clymer-DeBellis Javascript benchmark test page you sent me, to test the functions I am trying to run.  When I run it, my CPU pegs at 100% for the entire (long) time it loops.  The curious thing is that the "Looping..." message that writes to the text field never appears.  The CPU pegs before that gets written.  Weird, since that call takes place before the loop starts.

Bryan

Author

Commented:
Oh, and I am on Win NT 4.0, 384 meg RAM, on a Compaq EN C600.
Interesting... I don't really know what to tell you in this case.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial