Alternative to eval

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • HikksNotAtHome

    Alternative to eval

    This is a very simplified example of an Intranet application. But, is there an
    easier (or more efficient) way of getting the decimal equivalent of a fraction?

    The actual function gets the select values, this one is a simplified version
    where its passed.

    function checkIt(selVal) {
    valueInDec1 = eval(selVal);
    //do some calculations here with valueInDec1
    }

    <select onchange="check It(this.value)" >
    <option value="0">0</option>
    <option value="1/16">1/16</option>
    <option value="1/8">1/8</option>
    ...............
    <option value="7/8">7/8</option>
    <option value="15/16">15/16</option>
    </select>

    I know that I could change it and have it look up the decimal equivalent for
    the fraction, with an Object or an Array. I could also split the value on the /
    and convert them to numbers, do the division, and get the decimal.

    I discounted the Object/Array approach (and may go back to it, but doubt it).
    The reason is that its not just 16ths. Some of the selects are 37ths, some are
    7ths, one of them has 128ths in it. Simply put, I don't think that maintaining
    10+ objects to contain the decimals is efficient (but open to that approach).
    Also, its subject to get some added (different denominators), and some removed.

    The split approach just doesn't seem to be as efficient though.

    function checkIt(selVal) {
    myNumber = selVal.split('/')
    decimalForm = parseFloat(myNu mber[0])/parseFloat(myNu mber[1])
    //do some calculations here with valueInDec1
    }

    When the form gets submitted, it has to be in fractional form. I have no
    control over the way the selects get generated so I am kind of stuck trying to
    do it client side.



    Thoughts, suggestions, comments?
    --
    Randy
    All code posted is dependent upon the viewing browser
    supporting the methods called, and Javascript being enabled.
  • Lee

    #2
    Re: Alternative to eval

    HikksNotAtHome said:[color=blue]
    >
    >This is a very simplified example of an Intranet application. But, is there an
    >easier (or more efficient) way of getting the decimal equivalent of a fraction?
    >
    >The actual function gets the select values, this one is a simplified version
    >where its passed.
    >
    >function checkIt(selVal) {
    >valueInDec1 = eval(selVal);
    >//do some calculations here with valueInDec1
    >}
    >
    ><select onchange="check It(this.value)" >
    > <option value="0">0</option>
    > <option value="1/16">1/16</option>
    > <option value="1/8">1/8</option>
    >............ ..
    > <option value="7/8">7/8</option>
    > <option value="15/16">15/16</option>
    ></select>[/color]


    The most efficient solution would seem to be:

    <select onchange="check It(this.value)" >
    <option value="0">0</option>
    <option value="0.0625"> 1/16</option>
    <option value="0.125">1/8</option>
    ...............
    <option value="0.875">7/8</option>
    <option value="0.9375"> 15/16</option>
    </select>

    Comment

    • HikksNotAtHome

      #3
      Re: Alternative to eval

      In article <bhog5102t3b@dr n.newsguy.com>, Lee <REM0VElbspamtr ap@cox.net>
      writes:
      [color=blue]
      >The most efficient solution would seem to be:
      >
      ><select onchange="check It(this.value)" >
      > <option value="0">0</option>
      > <option value="0.0625"> 1/16</option>
      > <option value="0.125">1/8</option>
      >............ ..
      > <option value="0.875">7/8</option>
      > <option value="0.9375"> 15/16</option>
      ></select>[/color]

      I agree with you 100%. I have no control over how the select is generated
      though. If I loop through the select and options and programatically change
      them to decimals, I have to convert them back to fractions (or, swap them with
      the text of the option) so that when the form gets submitted, I get the
      fraction instead of the decimal. The eval still seems to be more efficient
      though, in the end. ::sigh::
      --
      Randy
      All code posted is dependent upon the viewing browser
      supporting the methods called, and Javascript being enabled.

      Comment

      • Steve van Dongen

        #4
        Re: Alternative to eval

        On 17 Aug 2003 17:55:11 GMT, hikksnotathome@ aol.com (HikksNotAtHome )
        wrote:
        [color=blue]
        >This is a very simplified example of an Intranet application. But, is there an
        >easier (or more efficient) way of getting the decimal equivalent of a fraction?
        >
        >I know that I could change it and have it look up the decimal equivalent for
        >the fraction, with an Object or an Array. I could also split the value on the /
        >and convert them to numbers, do the division, and get the decimal.
        >
        >I discounted the Object/Array approach (and may go back to it, but doubt it).
        >The reason is that its not just 16ths. Some of the selects are 37ths, some are
        >7ths, one of them has 128ths in it. Simply put, I don't think that maintaining
        >10+ objects to contain the decimals is efficient (but open to that approach).
        >Also, its subject to get some added (different denominators), and some removed.
        >
        >The split approach just doesn't seem to be as efficient though.
        >
        >function checkIt(selVal) {
        >myNumber = selVal.split('/')
        >decimalForm = parseFloat(myNu mber[0])/parseFloat(myNu mber[1])
        >//do some calculations here with valueInDec1
        >}
        >
        >When the form gets submitted, it has to be in fractional form.[/color]

        The Object/Array approach involves a fair bit of overhead, either in
        download time if all the contents are hardcoded, or time if they are
        generated at some point.

        As far as parsing the string goes, I've always considered compiled
        code to be faster than script-based parsing; split may not do as bad
        as you think.

        Usually I recommend against using eval because there is almost always
        a clearly better way of accomplishing the goal, but in this case I
        suspect eval will be equal to or better than any other method, plus,
        it appears that the input strings are static, so I think eval is the
        way to go.

        Regards,
        Steve

        Comment

        • Richard Cornford

          #5
          Re: Alternative to eval

          "HikksNotAtHome " <hikksnotathome @aol.com> wrote in message
          news:2003081713 5511.29815.0000 0053@mb-m21.aol.com...
          <snip>[color=blue]
          > function checkIt(selVal) {
          > valueInDec1 = eval(selVal);
          > //do some calculations here with valueInDec1
          > }[/color]

          If you just want to avoid the word "eval" appearing in your source code
          you could use:-

          valueInDec1 = new Function ('return ('+selVal+');') ();

          - but that will perform worse that eval. And the Function constructor
          will probably use eval internally so it is really no more than avoiding
          eval by name.

          <snip>[color=blue]
          > function checkIt(selVal) {
          > myNumber = selVal.split('/')
          > decimalForm = parseFloat(myNu mber[0])/parseFloat(myNu mber[1])
          > //do some calculations here with valueInDec1
          > }[/color]

          Unary + is about 4 times faster at string to number conversion than
          parseFloat, so:-

          decimalForm = (+myNumber[0])/(+myNumber[1]);

          -should be fractionally quicker. But then the division operator requires
          numeric operands so it will type-convert anyway so just:-

          decimalForm = (myNumber[0]/myNumber[1]);

          - will do.

          Generally I can't think of a non-eval approach that is better than the
          split-and-divide function above.

          Richard.


          Comment

          • HikksNotAtHome

            #6
            Re: Alternative to eval

            In article <bhp9vi$fe2$1$8 300dec7@news.de mon.co.uk>, "Richard Cornford"
            <Richard@litote s.demon.co.uk> writes:
            [color=blue]
            >Unary + is about 4 times faster at string to number conversion than
            >parseFloat, so:-
            >
            >decimalForm = (+myNumber[0])/(+myNumber[1]);
            >
            >-should be fractionally quicker. But then the division operator requires
            >numeric operands so it will type-convert anyway so just:-
            >
            >decimalForm = (myNumber[0]/myNumber[1]);[/color]

            The difference I see, in testing, of these two:

            decimalForm = (myNumber[0]/myNumber[1]);
            decimalForm = parseFloat(myNu mber[0])/parseFloat(myNu mber[1])

            Is in the 50-60 ms range, on 400-500 ms, The more passes, the stranger the
            results get.
            [color=blue]
            >- will do.
            >
            >Generally I can't think of a non-eval approach that is better than the
            >split-and-divide function above.[/color]

            Changing the test that I posted to
            decimalForm = (myNumber[0]/myNumber[1]);
            instead of the parseFloat's, I still get 440-500 milliseconds on 10,000 passes.

            I do see a difference with/without the parseFloat though (about 50-60
            milliseconds on 10,000 passes).

            With eval, I get in the range of 110 - 220. Which actually makes eval faster
            than the split/divide method in any form.

            Upping it to 50,000 passes, I get these results:

            Test1:
            eval took 1100 milliseconds
            split took 8070 milliseconds
            split with parseFloat took 8020 milliseconds
            split with parseInt took 8020 milliseconds

            Test2:
            eval took 1050 milliseconds
            split took 7960 milliseconds
            split with parseFloat took 8020 milliseconds
            split with parseInt took 8180 milliseconds

            Test3:
            eval took 1090 milliseconds
            split took 7910 milliseconds
            split with parseFloat took 8080 milliseconds
            split with parseInt took 8020 milliseconds

            Test4:
            eval took 550 milliseconds
            split took 7860 milliseconds
            split with parseFloat took 7960 milliseconds
            split with parseInt took 7970 milliseconds

            Test5:
            eval took 1040 milliseconds
            split took 8130 milliseconds
            split with parseFloat took 8020 milliseconds
            split with parseInt took 8130 milliseconds

            The test page I used can be found at:
            <URL: http://members.aol.com/hikksnotathom...est/index.html />
            Its set at 50,000 passes, view-source: may be a better way to get to it than
            letting it potentially lock up a browser.
            I added a 4th test, using parseInt instead of parseFloat, just for
            kicks/giggles.

            I had a new Function test in it but it was killing it, 11,000+ milliseconds (as
            you guessed it would do), so I took it out.

            But I wasn't avoiding eval for the sake of avoiding it. When I first tried it,
            I actually expected it to be slower, and got to looking at it, and thinking
            about what it was actually doing, and then started testing it. Saw where eval
            was faster, so I wanted other opinions on it. There may even be a flaw in my
            test itself?


            --
            Randy
            All code posted is dependent upon the viewing browser
            supporting the methods called, and Javascript being enabled.

            Comment

            • Richard Cornford

              #7
              Re: Alternative to eval

              "HikksNotAtHome " <hikksnotathome @aol.com> wrote in message
              news:2003081721 5411.15462.0000 2311@mb-m06.aol.com...
              <snip>[color=blue]
              > alerts 330 and 500 for me, which indicates eval is faster. But
              >thats on a 2.2 Ghz Machine with 256mbs Ram. Will test it again
              >tomorrow at work, on a slower machine, just to see how much
              >difference it makes. But it can only make a bigger difference.[/color]
              <snip>

              It looks to me like the results vary considerably depending on the
              browser. For IE eval is quickest, on Opera 7 and Mozilla 1.3 split
              followed by division comes out on top (500 Mhz PIII Win 98).

              Taking:-
              myNumber = tempObj[c].split('/')
              N = myNumber[0]/myNumber[1];
              - as the basis for comparison (100% on each browser)
              IE = 100%
              Op = 100%
              Mz = 100%

              myNumber = tempObj[c].split('/')
              N = (+myNumber[0])/(+myNumber[1]);
              IE = 98.74%
              Op = 98.36%
              Mz = 100%

              myNumber = tempObj[c].split('/')
              N = parseFloat(myNu mber[0])/parseFloat(myNu mber[1]);
              IE = 108.26%
              Op = 118.03%
              Mz = 109.52%

              N = eval(tempObj[i]);
              IE = 17.50%
              Op = 154.10%
              Mz = 122.22%

              N = new Function('retur n ('+tempObj[i]+');')();
              IE = 163.58%
              Op = 286.88%
              Mz = 152.38%

              For comparison, this is my test page:-

              <html>
              <head>
              <title></title>
              <script type="text/javascript">
              var frm = null;
              var fncts = ['emptyL','evalV ersion','Functi onObject',
              'splitNparseFlo at','splitNunar yPlus','splitNd ivide'];
              var running = false;

              function setButtons(bl){
              frm['loopLimit'].disabled = bl;
              var sw = frm['bt'];
              if(typeof sw.length == 'undefined'){
              sw = [sw];
              }
              for(var c = 0;c < sw.length;c++){
              sw[c].disabled = bl;
              }
              }

              var tempObj = new Object();
              function doTests(){
              if(!running){
              var t = ['','/',''];
              frm = document.forms['f'].elements;
              setButtons(true );
              t[2] = +frm['loopLimit'].value;

              for (var k=0;k<t[2];k++){
              t[0] = k;
              tempObj[k]= t.join('');
              }
              frm["Dur0"].value = '';frm["Avr0"].value = '';
              for(var c = 1;c < fncts.length;c+ +){
              frm["Dur"+c].value = '';
              frm["Avr"+c].value = '';
              frm["CAvr"+c].value = '';
              frm["PAvr"+c].value = '';
              frm["Res"+c].value = '';
              }
              running = true;
              act(0);
              }
              }
              function act(p){
              /* setTimeout is used to minimise the occurrences
              of 'a script on this page is running slow' dialogs. */
              if(p >= fncts.length){
              setTimeout('rep ort()',100);
              }else{
              setTimeout((fnc ts[p]+'('+p+');'),20 0);
              }
              }
              function report(){
              var lim = +frm['loopLimit'].value;
              var emDur = +frm["Dur0"].value
              var unaC = (frm["Dur"+(fncts.le ngth-1)].value - emDur) / lim;
              frm["CAvr"+(fncts.l ength-1)].value = unaC;
              frm["PAvr"+(fncts.l ength-1)].value = '100';
              for(var c = 1;c < (fncts.length-1);c++){
              if(frm["Cb"+c].checked){
              var evaC = (frm["Dur"+c].value - emDur) / lim;
              frm["CAvr"+c].value = evaC;
              frm["PAvr"+c].value = ((evaC/unaC)*100);
              }else{
              frm["CAvr"+c].value = 'X';
              frm["PAvr"+c].value = 'X';
              }
              }
              setButtons(fals e);
              running = false;
              }
              function emptyL(p){
              var lim = +frm['loopLimit'].value;
              var totTime,stTime = new Date().getTime( );
              for(var c = 0;c < lim;c++){
              ;
              }
              totTime = (new Date().getTime( ) - stTime)
              frm["Dur0"].value = totTime;
              frm["Avr0"].value = (totTime/lim);
              act(p+1);
              }
              function evalVersion(p){
              if(frm['Cb'+p].checked){
              var lim = +frm['loopLimit'].value;
              var N;
              var totTime,stTime = new Date().getTime( );
              for(var c = 0;c < lim;c++){
              N = eval(tempObj[c]);
              }
              totTime = (new Date().getTime( ) - stTime)
              frm["Dur"+p].value = totTime;
              frm["Avr"+p].value = (totTime/lim);
              frm["Res"+p].value = N;
              }else{
              frm["Dur"+p].value = 'X';
              frm["Avr"+p].value = 'X';
              frm["Res"+p].value = 'X';
              }
              act(p+1);
              }
              function FunctionObject( p){
              if(frm['Cb'+p].checked){
              var lim = +frm['loopLimit'].value;
              var N;
              var totTime,stTime = new Date().getTime( );
              for(var c = 0;c < lim;c++){
              N = new Function('retur n ('+tempObj[c]+');')();
              }
              totTime = (new Date().getTime( ) - stTime)
              frm["Dur"+p].value = totTime;
              frm["Avr"+p].value = (totTime/lim);
              frm["Res"+p].value = N;
              }else{
              frm["Dur"+p].value = 'X';
              frm["Avr"+p].value = 'X';
              frm["Res"+p].value = 'X';
              }
              act(p+1);
              }
              function splitNparseFloa t(p){
              if(frm['Cb'+p].checked){
              var lim = +frm['loopLimit'].value;
              var N,temp;
              var totTime,stTime = new Date().getTime( );
              for(var c = 0;c < lim;c++){
              temp = tempObj[c].split('/')
              N = parseFloat(temp[0])/parseFloat(temp[1]);
              }
              totTime = (new Date().getTime( ) - stTime)
              frm["Dur"+p].value = totTime;
              frm["Avr"+p].value = (totTime/lim);
              frm["Res"+p].value = N;
              }else{
              frm["Dur"+p].value = 'X';
              frm["Avr"+p].value = 'X';
              frm["Res"+p].value = 'X';
              }
              act(p+1);
              }
              function splitNunaryPlus (p){
              if(frm['Cb'+p].checked){
              var lim = +frm['loopLimit'].value;
              var N,temp;
              var totTime,stTime = new Date().getTime( );
              for(var c = 0;c < lim;c++){
              temp = tempObj[c].split('/')
              N = (+temp[0])/(+temp[1]);
              }
              totTime = (new Date().getTime( ) - stTime)
              frm["Dur"+p].value = totTime;
              frm["Avr"+p].value = (totTime/lim);
              frm["Res"+p].value = N;
              }else{
              frm["Dur"+p].value = 'X';
              frm["Avr"+p].value = 'X';
              frm["Res"+p].value = 'X';
              }
              act(p+1);
              }
              function splitNdivide(p) {
              if(frm['Cb'+p].checked){
              var lim = +frm['loopLimit'].value;
              var N,temp;
              var totTime,stTime = new Date().getTime( );
              for(var c = 0;c < lim;c++){
              temp = tempObj[c].split('/')
              N = temp[0]/temp[1];
              }
              totTime = (new Date().getTime( ) - stTime)
              frm["Dur"+p].value = totTime;
              frm["Avr"+p].value = (totTime/lim);
              frm["Res"+p].value = N;
              }else{
              frm["Dur"+p].value = 'X';
              frm["Avr"+p].value = 'X';
              frm["Res"+p].value = 'X';
              }
              act(p+1);
              }
              </script>
              </head>
              <body>
              <p>
              <form name="f" action="#">
              Loop Length = <input type="text" value="50000"
              name="loopLimit "> Some browsers will put up an &quot;A script on
              this page is making the browser run slowly&quot; dialog. If this
              happens the results for the test will be invalid and a shorter loop
              will be needed. However, JavaScript Date objects do not tend to be
              accurate to less than 10 milliseconds so duration results that are
              not different by at least 20 milliseconds (and preferably 100+) are
              not necessarily meaningful and a longer loop may be needed to acquire
              useful results.<br><br >
              <input type="button" value="Test" name="bt" onclick="doTest s();">
              Repeat tests to reduce/expose the influence of background tasks.
              <br><br>
              Empty Loop Duration (milliseconds) = <input type="text" value="X"
              name="Dur0"><br >
              Empty Loop Average (milliseconds) = <input type="text" value="X"
              name="Avr0" size="22"><br>< br>
              Test <code>N = eval(tempObj[i]);</code> ? <input type="checkbox"
              name="Cb1" checked><br>
              <code>N = eval(tempObj[i]);</code> Duration (milliseconds) =
              <input type="text" value="X" name="Dur1"><br >
              <code>N = eval(tempObj[i]);</code> Average (milliseconds) =
              <input type="text" value="X" name="Avr1" size="22"><br>
              (result = <input type="text" value="X" name="Res1" size="22">)<br> <br>
              Test <code>N = new Function('retur n ('+tempObj[i]+');')();</code> ?
              <input type="checkbox" name="Cb2"><br>
              <code>N = new Function('retur n ('+tempObj[i]+');')();</code>
              Duration (milliseconds) = <input type="text" value="X"
              name="Dur2"><br >
              <code>N = new Function('retur n ('+tempObj[i]+');')();</code>
              Average (milliseconds) = <input type="text" value="X"
              name="Avr2" size="22"><br>
              (result = <input type="text" value="X" name="Res2" size="22">)<br> <br>
              Test <code>N = parseFloat(myNu mber[0])/parseFloat(myNu mber[1]);</code>
              ? <input type="checkbox" name="Cb3" checked><br>
              <code>N = parseFloat(myNu mber[0])/parseFloat(myNu mber[1]);</code>
              Duration (milliseconds) = <input type="text" value="X"
              name="Dur3"><br >
              <code>N = parseFloat(myNu mber[0])/parseFloat(myNu mber[1]);</code>
              Average (milliseconds) = <input type="text" value="X"
              name="Avr3" size="22"><br>
              (result = <input type="text" value="X" name="Res3" size="22">)<br> <br>
              Test <code>N = (+myNumber[0])/(+myNumber[1]);</code> ? <input
              type="checkbox" name="Cb4" checked><br>
              <code>N = (+myNumber[0])/(+myNumber[1]);</code>
              Duration (milliseconds) = <input type="text" value="X"
              name="Dur4"><br >
              <code>N = (+myNumber[0])/(+myNumber[1]);</code>
              Average (milliseconds) = <input type="text" value="X"
              name="Avr4" size="22"><br>
              (result = <input type="text" value="X" name="Res4" size="22">)<br> <br>
              Test <code>N = myNumber[0]/myNumber[1];</code> ?
              <input type="checkbox" name="Cb5" checked><br>
              <code>N = myNumber[0]/myNumber[1];</code>
              Duration (milliseconds) = <input type="text" value="X"
              name="Dur5"><br >
              <code>N = myNumber[0]/myNumber[1];</code>
              Average (milliseconds) = <input type="text" value="X"
              name="Avr5" size="22"><br>
              (result = <input type="text" value="X" name="Res5" size="22">)<br> <br>
              <input type="button" value="Test" name="bt" onclick="doTest s();">
              Repeat tests to reduce/expose the influence of background tasks.
              <br><br>
              Results: (duration of test - duration of empty loop) / loop length<br>
              <code>N = eval(tempObj[i]);</code> Average (milliseconds) =
              <input type="text" value="X" name="CAvr1" size="22"><br>
              <code>N = new Function('retur n ('+tempObj[i]+');')();</code>
              Average (milliseconds) = <input type="text" value="X"
              name="CAvr2" size="22"><br>
              <code>N = parseFloat(myNu mber[0])/parseFloat(myNu mber[1]);</code>
              Average (milliseconds) = <input type="text" value="X"
              name="CAvr3" size="22"><br>
              <code>N = (+myNumber[0])/(+myNumber[1]);</code> Average (milliseconds)
              = <input type="text" value="X" name="CAvr4" size="22"><br>
              <code>N = myNumber[0]/myNumber[1];</code> Average (milliseconds) =
              <input type="text" value="X" name="CAvr5" size="22"><br>< br>
              Differences (<code>((Math.r ound(Math.rando m()))||-1)</code> = 100%)
              <br><code>N = eval(tempObj[i]);</code> = <input type="text" value="X"
              name="PAvr1" size="22">%<br>
              <code>N = new Function('retur n ('+tempObj[i]+');')();</code> =
              <input type="text" value="X" name="PAvr2" size="22">%<br>
              <code>N = parseFloat(myNu mber[0])/parseFloat(myNu mber[1]);</code> =
              <input type="text" value="X" name="PAvr3" size="22">%<br>
              <code>N = (+myNumber[0])/(+myNumber[1]);</code> = <input type="text"
              value="X" name="PAvr4" size="22">%<br>
              <code>N = myNumber[0]/myNumber[1];</code> = <input type="text"
              value="X" name="PAvr5" size="22">%<br>
              </form>
              </p>
              </body>
              </html>

              Richard.


              Comment

              • Dr John Stockton

                #8
                Re: Alternative to eval

                JRS: In article <20030817135511 .29815.00000053 @mb-m21.aol.com>, seen in
                news:comp.lang. javascript, HikksNotAtHome <hikksnotathome @aol.com>
                posted at Sun, 17 Aug 2003 17:55:11 :-[color=blue]
                >This is a very simplified example of an Intranet application. But, is there an
                >easier (or more efficient) way of getting the decimal equivalent of a fraction?
                >
                >The actual function gets the select values, this one is a simplified version
                >where its passed.
                >
                >function checkIt(selVal) {
                >valueInDec1 = eval(selVal);
                >//do some calculations here with valueInDec1
                >}
                >
                ><select onchange="check It(this.value)" >
                > <option value="0">0</option>
                > <option value="1/16">1/16</option>
                > <option value="1/8">1/8</option>
                >............ ..
                > <option value="7/8">7/8</option>
                > <option value="15/16">15/16</option>
                ></select>[/color]


                Don't be afraid of eval. In this case you need to evaluate a string
                chosen at run time, for which eval is appropriate. Pre-conversion of
                value to a numeric literal form gives long numbers or inaccuracy, if the
                denominator is not a power of two.

                Speed does NOT matter, since the evaluation only occurs after a manual
                operation. Here, efficiency is code shortness.

                --
                © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 MIME. ©
                Web <URL:http://www.merlyn.demo n.co.uk/> - FAQqish topics, acronyms & links;
                some Astro stuff via astro.htm, gravity0.htm; quotes.htm; pascal.htm; &c, &c.
                No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.

                Comment

                • HikksNotAtHome

                  #9
                  Re: Alternative to eval

                  In article <20030818000514 .00545.00000076 @mb-m02.aol.com>,
                  hikksnotathome@ aol.com (HikksNotAtHome ) writes:
                  [color=blue]
                  >But I wasn't avoiding eval for the sake of avoiding it. When I first tried
                  >it, I actually expected it to be slower, and got to looking at it, and[/color]
                  thinking[color=blue]
                  >about what it was actually doing, and then started testing it. Saw where eval
                  >was faster, so I wanted other opinions on it. There may even be a flaw in my
                  >test itself?[/color]

                  Many thanks to everyone who replied.

                  For now, I am going to go ahead and use the split/divide approach, not because
                  of speed (I dont see how it can make *any* perceptible difference to the user,
                  not when you start talking in the decimal range of ms to execute it once,
                  either way), for no other reason than my own sanity with regards to eval. I
                  have spent the better part of 6 months fighting the use of eval. It took me 2
                  months to show them that I could get at any form element, no matter how
                  bastardized they made it, without eval, so instead of going back and saying
                  "Hey, in IE, eval actually does it faster", I will just use the split/divide
                  method. Then, if its ever converted (the intranet), to a non-IE environment, I
                  will have the fastest of the 2 already in place.

                  Again, thanks to all. Now, I can get to hacking/whacking at Jims crypto page.
                  --
                  Randy
                  All code posted is dependent upon the viewing browser
                  supporting the methods called, and Javascript being enabled.

                  Comment

                  • Grant Wagner

                    #10
                    Re: Alternative to eval

                    HikksNotAtHome wrote:
                    [color=blue]
                    > In article <20030818000514 .00545.00000076 @mb-m02.aol.com>,
                    > hikksnotathome@ aol.com (HikksNotAtHome ) writes:
                    >[color=green]
                    > >But I wasn't avoiding eval for the sake of avoiding it. When I first tried
                    > >it, I actually expected it to be slower, and got to looking at it, and[/color]
                    > thinking[color=green]
                    > >about what it was actually doing, and then started testing it. Saw where eval
                    > >was faster, so I wanted other opinions on it. There may even be a flaw in my
                    > >test itself?[/color]
                    >
                    > Many thanks to everyone who replied.
                    >
                    > For now, I am going to go ahead and use the split/divide approach, not because
                    > of speed (I dont see how it can make *any* perceptible difference to the user,
                    > not when you start talking in the decimal range of ms to execute it once,
                    > either way), for no other reason than my own sanity with regards to eval. I
                    > have spent the better part of 6 months fighting the use of eval. It took me 2
                    > months to show them that I could get at any form element, no matter how
                    > bastardized they made it, without eval, so instead of going back and saying
                    > "Hey, in IE, eval actually does it faster", I will just use the split/divide
                    > method. Then, if its ever converted (the intranet), to a non-IE environment, I
                    > will have the fastest of the 2 already in place.
                    >
                    > Again, thanks to all. Now, I can get to hacking/whacking at Jims crypto page.
                    > --
                    > Randy[/color]

                    May I also suggest that instead of:

                    <select onchange="func( this.value);">

                    you use:

                    <select onchange="func( this.options[this.selectedIn dex].value);">


                    :)

                    --
                    | Grant Wagner <gwagner@agrico reunited.com>

                    * Client-side Javascript and Netscape 4 DOM Reference available at:
                    *


                    * Internet Explorer DOM Reference available at:
                    *
                    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.


                    * Netscape 6/7 DOM Reference available at:
                    * http://www.mozilla.org/docs/dom/domref/
                    * Tips for upgrading JavaScript for Netscape 7 / Mozilla
                    * http://www.mozilla.org/docs/web-deve...upgrade_2.html


                    Comment

                    Working...