Object vs string comparison

JavaScript performance comparison

Test case created by Isma

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var
    dummy,
    a1 = {},
    a2 = {},
    a3 = {},
    a4 = {},
    v1 = a1,
    v2 = a2,
    v3 = a3,
    v4 = a4,
    s1 = 'asdfghjk1',
    s2 = 'asdfghjk2',
    s3 = 'asdfghjk3',
    s4 = 'asdfghjk4';
};
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
objects
if (v1 == a1 && v2 == a2 && v3 == a3 && v4 == a4)
  dummy = 'a';
pending…
strings
if (s1 == 'asdfghjk1' && s2 == 'asdfghjk2' && s3 == 'asdfghjk3' && s4 == 'asdfghjk4')
  dummy = 'a';
pending…
strict object
if (v1 === a1 && v2 === a2 && v3 === a3 && v4 === a4)
  dummy = 'a';
pending…
strict string
if (s1 === 'asdfghjk1' && s2 === 'asdfghjk2' && s3 === 'asdfghjk3' && s4 === 'asdfghjk4')
  dummy = 'a';
pending…

You can edit these tests or add even more tests to this page by appending /edit to the URL.

Compare results of other browsers

0 comments

Add a comment