inefficient to check value of a checkbox?

Discussion in 'Javascript' started by Kourosh, May 26, 2006.

  1. Kourosh

    Kourosh Guest

    I have a big loop that checks the value of a checkbox several times
    (1000+ times)
    I'm just wondering, would it be any more efficient to save the value of
    the checkbox outside the loop and the read that variable inside the
    loop instead?

    ie, I have this
    for (var i=0;...)
    doStuff (form1.checkbox1.checked);


    versus
    var chk = form1.checkbox1.checked;
    for (var i=0;...)
    doStuff (chk);
    Kourosh, May 26, 2006
    #1
    1. Advertising

  2. Kourosh

    Randy Webb Guest

    Kourosh said the following on 5/26/2006 2:54 PM:
    > I have a big loop that checks the value of a checkbox several times
    > (1000+ times)
    > I'm just wondering, would it be any more efficient to save the value of
    > the checkbox outside the loop and the read that variable inside the
    > loop instead?
    >
    > ie, I have this
    > for (var i=0;...)
    > doStuff (form1.checkbox1.checked);
    >
    >
    > versus
    > var chk = form1.checkbox1.checked;
    > for (var i=0;...)
    > doStuff (chk);
    >


    Do the second. It keeps from having to look up that property 1000 or so
    times and as such will *always* be faster.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, May 26, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. News
    Replies:
    17
    Views:
    433
    Larry Bates
    Apr 14, 2006
  2. Lone Wolf
    Replies:
    5
    Views:
    680
    Dennis Lee Bieber
    Dec 4, 2006
  3. Joshua J. Kugler

    Is shelve/dbm supposed to be this inefficient?

    Joshua J. Kugler, Aug 2, 2007, in forum: Python
    Replies:
    1
    Views:
    325
    Marc 'BlackJack' Rintsch
    Aug 2, 2007
  4. Bruno Desthuilliers

    Inefficient summing

    Bruno Desthuilliers, Oct 8, 2008, in forum: Python
    Replies:
    10
    Views:
    435
    Alexander Schmolck
    Oct 10, 2008
  5. Bryan
    Replies:
    8
    Views:
    348
    Bryan
    Nov 3, 2008
Loading...

Share This Page