Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #16936

Re: Built-in native method

From Cezary Tomczyk <cezary.tomczyk@gmail.com>
Newsgroups comp.lang.javascript
Subject Re: Built-in native method
Date 2012-10-28 22:03 +0100
Organization Aioe.org NNTP Server
Message-ID <k6k6k4$nrq$1@speranza.aioe.org> (permalink)
References (5 earlier) <1886339.7pA5ev5edD@PointedEars.de> <k6jqlh$nlb$1@speranza.aioe.org> <270317591.RgZlF00zI7@PointedEars.de> <k6k0n0$8eb$1@speranza.aioe.org> <1626770.WBuXB4FIxE@PointedEars.de>

Show all headers | View raw


W dniu 2012-10-28 21:23, Thomas 'PointedEars' Lahn pisze:
> Cezary Tomczyk wrote:
>
>> W dniu 2012-10-28 20:10, Thomas 'PointedEars' Lahn pisze:
>>> Cezary Tomczyk wrote:
>>>> I even extended little bit this test
>>>> http://jsperf.com/typeof-equals-triple-double by comparing two different
>>>> objects and IE9, Google Chrome 22.0.1229.94, Opera 12.02 for 4 tests are
>>>> more or less similar, but Firefox 16.0.2 surprised me little bit:
>>>>
>>>> triple equals: 8167 Ops/sec
>>>> double equals: 4752 Ops/sec
>>>> triple equals - different objects: 90830 Ops/sec
>>>> double equals - different objects: 89815 Ops/sec
>>>>
>>>> All of them tested on Windows 7, 64 bit.
>>>>
>>>> What a huge difference. Weird for me, little bit.
>>>
>>> 1. You are benchmarking the wrong feature there.
>>
>> Ok, maybe I should do two separate tests.
>
> You wanted to test `==' vs. `==='.  What you are actually testing there is
> `typeof ""' vs. `typeof {}'.  Keep in mind that the `typeof' operation
> *always* results in a string value.

OMG, you have absolutely right. What I was thinking about during 
creating those tests, I don't know :-)

Ok, now should be better:
http://jsperf.com/three-double-equal

And the name of this test should not contains "typeof" word any more.

>>> 2. I do not think you need loops with jsperf.
>>
>> Is there better way?
>
> Yes, omit them.  jsperf loops by itself, and if it is any good it uses
> nested loops.

I removed loops. Thanks for tip.

>>> 3. Never trust benchmarks.
>>
>> Then one of the alternative is to measure time by using new
>> Date().getTime() :/
>
> No, the reasonable alternative is to profile real code under real conditions
> if and when slow speed becomes a problem.  A V8 JavaScript profiler is
> included in the Chromium/Chrome Developer Tools; Firebug contains one for
> SpiderMonkey as well.  Premature optimization is the root of all evil. [tm]

Using "profiler" that's probably the best way. As for "Premature 
optimization" generally speaking I agree, but first of all "Premature 
optimization" must be somehow defined, because every developer 
understand it in a very different way. Let's say that this is just a 
different topic.

> The issue of `==' vs. `===' is not so much speed; it is the outcome of
> either operation, which can be unexpected in the former case.

Test results, even if it comes from jsperf, showing that mostly === is 
faster around from 70% up to 100% than ==.

-- 
Cezary Tomczyk
http://www.ctomczyk.pl/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-19 22:07 +0200
  Re: Built-in native method JJ <jaejunks_at@_googlemail_dot._com> - 2012-10-21 06:44 +0000
    Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-21 18:46 +0200
    Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-21 19:37 +0200
      Re: Built-in native method Andreas Bergmaier <andber93@web.de> - 2012-10-22 15:47 +0200
        Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-22 18:00 +0200
          Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 02:17 +0100
            Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-24 22:17 +0200
              Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-25 00:32 +0200
  Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-24 02:15 +0100
    Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-24 22:35 +0200
      Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-25 00:03 +0200
        Re: Built-in native method Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-10-26 03:58 -0700
          Re: Built-in native method RobG <rgqld@iinet.net.au> - 2012-10-29 16:39 -0700
        Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 15:32 +0100
          Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 17:05 +0100
            Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 18:39 +0100
              Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 20:10 +0100
                Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 20:23 +0100
                Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 21:23 +0100
                Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 22:03 +0100
        Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 15:49 +0100
          Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 17:12 +0100
            Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 17:49 +0100
              Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 18:07 +0100
                Re: Built-in native method Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2012-10-28 19:22 +0100
                Re: Built-in native method Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-10-28 19:53 +0100

csiph-web