json parsing and stringifying

JavaScript performance comparison

Test case created

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var isValid = function(s) {
      // All empty whitespace is not valid.
      if (/^\s*$/.test(s)) {
        return false;
      }
   
      // Don't make these static since they have the global flag.
      var backslashesRe = /\\["\\\/bfnrtu]/g;
      var simpleValuesRe =
          /"[^"\\\n\r\u2028\u2029\x00-\x08\x0a-\x1f]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
      var openBracketsRe = /(?:^|:|,)(?:[\s\u2028\u2029]*\[)+/g;
      var remainderRe = /^[\],:{}\s\u2028\u2029]*$/;
   
      return remainderRe.test(s.replace(backslashesRe, '@').
          replace(simpleValuesRe, ']').
          replace(openBracketsRe, ''));
    };
   
    var json = JSON.stringify({key: Math.random(), isError:  false , data: ["116910304844117268718",[,,"https://plus.FooBar.com/116910304844117268718","//lh4.FooBarusercontent.com/-tQJAx2-8rqE/AAAAAAAAAAI/AAAAAAAATH4/67EZ6xAu1Z0/photo.jpg",[[,,,,[]
    ,6]
    ,"Foo","Bar","Foo Bar",0]
    ,[[,,,,[]
    ,6]
    ,[["twitter"]
    ]
    ]
    ,[[,,,,[]
    ,6]
    ,"engineer"]
    ,[[,,,,[]
    ,6]
    ,[["FooBar","engineer",[[1,1,2010]
    ,[1,1,2012]
    ,1]
    ,""]
    ,["JSConf","",[[1,1,2010]
    ,[1,1,2012]
    ]
    ,""]
    ,["S2","Technical Director",[[1,1,2008]
    ,[1,1,2010]
    ]
    ,""]
    ,["ITC","engineer",[[1,1,2004]
    ,[1,1,2008]
    ]
    ,""]
    ,["Yo","CEO",[[1,1,2007]
    ,[1,1,2008]
    ]
    ,""]
    ]
    ]
    ,[[,,,,[]
    ,6]
    ,[["NUniversity","",[]
    ,""]
    ]
    ]
    ,[[,,,,[]
    ,6]
    ,"San Francisco",["Hamburg","Elmshorn","Abc, SD"]
    ,,["San Francisco",[,377749300,-1224194160,1]
    ]
    ,[["Hamburg",[,535538150,99915750,1]
    ]
    ,["Elmshorn",[,537552990,96562390,1]
    ]
    ,["Abc, SD",[,443683160,-1003509660,1]
    ]
    ]
    ]
    ,"//maps-api-ssl.FooBar.com/maps/api/staticmap?size\u003d195x150\u0026sensor\u003dfalse\u0026client\u003dFooBar-profiles\u0026language\u003den\u0026markers\u003dsize:small%7Ccolor:green%7C53.553815,9.991575%7C53.755299,9.656239%7C44.368316,-100.350966\u0026markers\u003dsize:small%7Ccolor:blue%7C37.77493,-122.419416\u0026signature\u003dYuGUlNbxvxoG5OXqnMKhkQgfRCw%3D",[[]
    ,[,,,,[]
    ,6]
    ,[,,,,[]
    ,6]
    ]
    ,[[,,,,[]
    ,6]
    ,["1-650-390-3497"]
    ,[]
    ,[]
    ,[]
    ,,["3338 17th St. Apt 207, 94110 San Francisco, CA, USA"]
    ,[]
    ,,[["Foo.Bar@gmail.com",1]
    ]
    ,[[,"3338 17th St. Apt 207, 94110 San Francisco, CA, USA"]
    ]
    ]
    ,[[,,,,[]
    ,6]
    ,[]
    ,[]
    ,[]
    ,[]
    ,,[]
    ,[]
    ,,[]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"Asynchronous Identity Disorder\u003cbr\u003e\u003cdiv\u003e\u003cspan style\u003d\"font-style:italic\"\u003eOpinions expressed here are my own, yadda, yadda.\u003c/span\u003e\u003c/div\u003e"]
    ,,[[,,,,[]
    ,6]
    ,"October 27",0,27,10]
    ,[[,,,,[]
    ,6]
    ,1]
    ,,[[,,,,[]
    ,6]
    ,""]
    ,,,[[,,,,[]
    ,6]
    ,5,0]
    ,[[,,,,[]
    ,6]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,0]
    ,[[,,,,[]
    ,6]
    ,0]
    ,[[,,,,[]
    ,6]
    ,1]
    ,,,,"116910304844117268718",1,,[[,,,,[]
    ,6]
    ,"Curing my asynchronous identity disorder at FooBar"]
    ,,[[,,,,[]
    ,6]
    ,[]
    ]
    ,,[[,,,,[]
    ,6]
    ,0]
    ,,,0,,,,[0,1,1,,1,1,,,1]
    ,1,[4,,0,0,0,[]
    ,,,0]
    ,[[,,,,[]
    ,6]
    ,"twitter"]
    ,1,,1,[[[[,,,,[]
    ,6]
    ,"http://www.nonblocking.io/","//s2.FooBarusercontent.com/s2/favicons?domain\u003dwww.nonblocking.io\u0026alt\u003dp","NonBlocking.io","me",0,["http://www.nonblocking.io/"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"http://twitter.com/twitter","//s2.FooBarusercontent.com/s2/favicons?domain\u003dtwitter.com\u0026alt\u003dp","Twitter","me",0,["http://twitter.com/twitter","sgn://twitter.com/?ident\u003dtwitter"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"http://www.quora.com/Foo-Bar","//s2.FooBarusercontent.com/s2/favicons?domain\u003dwww.quora.com\u0026alt\u003dp","Foo-Bar","me",0,["sgn://quora.com/?ident\u003dFoo-Bar","http://www.quora.com/Foo-Bar"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"http://www.linkedin.com/in/FooBar","//s2.FooBarusercontent.com/s2/favicons?domain\u003dwww.linkedin.com\u0026alt\u003dp","LinkedIn","me",0,["sgn://linkedin.com/?ident\u003dFooBar","http://www.linkedin.com/in/FooBar"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"https://github.com/twitter","//s2.FooBarusercontent.com/s2/favicons?domain\u003dgithub.com\u0026alt\u003dp","GitHub","me",0,["sgn://github.com/?ident\u003dtwitter","https://github.com/twitter"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"http://www.youtube.com/user/Foo1234123","//s2.FooBarusercontent.com/s2/favicons?domain\u003dwww.youtube.com\u0026alt\u003dp","Foo Bar","me",1,["sgn://youtube.com/?ident\u003dFoo1234123","http://www.youtube.com/user/Foo1234123"]
    ,[[2]
    ,[2]
    ]
    ]
    ]
    ,,[,,,,[]
    ,6]
    ]
    ,[[[[,,,,[]
    ,6]
    ,"http://www.JSConf.eu","//s2.FooBarusercontent.com/s2/favicons?domain\u003dwww.JSConf.eu\u0026alt\u003dp","JSConf EU","contributor-to",0,["http://www.JSConf.eu"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"http://jsconf.com/","//s2.FooBarusercontent.com/s2/favicons?domain\u003djsconf.com\u0026alt\u003dp","JSConf","contributor-to",0,["http://jsconf.com/"]
    ,[]
    ]
    ]
    ,,[,,,,[]
    ,6]
    ]
    ,[[[[,,,,[]
    ,6]
    ,"http://code.FooBar.com/p/joose-js/","//s2.FooBarusercontent.com/s2/favicons?domain\u003dcode.FooBar.com\u0026alt\u003dp","Joose - JavaScript Meta Object System","",0,["http://code.FooBar.com/p/joose-js/"]
    ,[]
    ]
    ,[[,,,,[]
    ,6]
    ,"http://blok.appspot.com/","//s2.FooBarusercontent.com/s2/favicons?domain\u003dblok.appspot.com\u0026alt\u003dp","blok.appspot.com","",0,["http://blok.appspot.com/"]
    ,[]
    ]
    ]
    ,,[,,,,[]
    ,6]
    ]
    ,1,,[[,,,,[]
    ,6]
    ,0]
    ,,,,,[[,,,,[]
    ,6]
    ,0]
    ,0,[2,[]
    ,["5819372865906803970",[0,0]
    ,1,,0]
    ]
    ,1,,[4,0]
    ,,,[[[,1,10000]
    ]
    ]
    ,,,,,[[1]
    ]
    ,"",[[,,,,[]
    ,6]
    ,""]
    ]
    ,"Foo.Bar@gmail.com",,"en",,,,,1,,1,,1,1,,,,,,"Foo Bar \u003cFoo.Bar@gmail.com\u003e",,,,1,,,1,2,,1,,,"WmgS6js9vMOsD1wK/ASOvW5_gecqmcBqZf",[4,0]
    ,0]
    });
};
</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
JSON.parse
JSON.parse(json)
pending…
eval
eval('(' + json + ')')
pending…
safer eval
isValid(json);
eval('(' + json + ')')
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