Re: JSLint and JavaScript: The Good Parts.



Whatever benchmarking you do, you'll want to do it in you target JS
engine. Each engine (Trace/JaegerMonkey, V8, Nitro, Carakan, MS) will
perform different ops at different speeds. This is because some are
JIT based systems, some are tracing systems, some simple interpretors,
and some are combinations.

I'm a web-app developer by profession -- about 90% of my coding day is
spent working with JavaScript. Although I agree with Owen that it can
be confusing "getting it right", I would suggest that it's best
practice. If you're checking if something is null, then it's anyway
often simpler to just use shorthand: if(blah) { }. Remember,
undefined, null, 0, '', and false are all "falsy" values -- everything
else is truthy. That means that if you're after a true boolean when
checking if something's falsy, you can just use !!blah.

It's just my two cents, but, because JavaScript is such a flexible
language, I do believe that one should always be completely aware of
what's going on -- in other words, use === unless you very, very
specifically want to allow type coercion. It's kind of like falling
through in switch statemenrs: it canbe realky, really useful, or it
can cause really obscure, hard-to-track-down bugs, the latter being,
in my experience, more common than the former.

- Barry
www.barryvan.com.au

On Monday, March 15, 2010, David Mulder <greatslovakia zoho com> wrote:
> When reading into this issue somebody suggested === would be faster than ==, I just finished running a very basic benchmark comparing == vs === as far as speed is concerned (string comparison). Unsurprisingly there isn't any speed difference, however the uncertainty of the results in === was far bigger (0.05 s with == and 0.3 s with ===), could anybody check whether this difference is reproducible or whether this is only some random problem with my system. (Tested with chromium on mac). I ran the following script 10 times for both == and ===, it's might be a bit simplistic, but there would have any big difference it should have come out.
>
> <script>start = (new Date()).getTime();string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
> string2 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
> for(i=0;i<10000;i++){ if(string===string2){     string=string+" ";     string2=string2+" ";           }
> }
>         stop = (new Date()).getTime();console.log(stop-start);</script>
> David Mulder
> On Mon, Mar 15, 2010 at 4:20 PM, David Mulder <greatslovakia zoho com> wrote:
>
> When reading into this issue somebody suggested === would be faster than ==, I just finished running a very basic benchmark comparing == vs === as far as speed is concerned (string comparison). Unsurprisingly there isn't any speed difference, however the uncertainty of the results in === was far bigger (0.05 s with == and 0.3 s with ===), could anybody check whether this difference is reproducible or whether this is only some random problem with my system. (Tested with chromium on mac). I ran the following script 10 times for both == and ===, it's might be a bit simplistic, but there would have any big difference it should have come out.
>
> <script>start = (new Date()).getTime();string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
>
> string2 = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
>
> for(i=0;i<10000;i++){ if(string===string2){     string=string+" ";     string2=string2+" ";
>       }       }
>         stop = (new Date()).getTime();
> console.log(stop-start);</script>
> David Mulder
> On Mon, Mar 15, 2010 at 4:03 PM, Owen Taylor <--
http://barryvan.com.au/
bvanoudtshoorn gmail com



-- 
http://barryvan.com.au/
bvanoudtshoorn gmail com


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]