JSON Parsing (v11)

Revision 11 of this benchmark created by Leonardo Dutra on


Preparation HTML

<script>
  var myjson = '{"mylist": [4, 8, 15, 16, 23, 42], "myobject": {"hello": "world"}, "myint": 23, "mystrlist": ["foo", "bar"]}',
      cachedEval = eval('(' + myjson + ')'),
      cachedFunction = (new Function('return ' + myjson)); // *deprecated
  
  function tuenti_decode(string, secure) {
   if (typeof string != "string" || !string.length) {
    return null;
   }
   if (secure && !/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/.test(string.replace(/\\./g, "@").replace(/"[^"\\\n\r]*"/g, ""))) {
    return null;
   }
   return eval("(" + string + ")");
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Evil
eval('(' + myjson + ')');
ready
JSON.parse
JSON.parse(myjson);
ready
new Function
(new Function('return ' + myjson))();
ready
Cached function (deprecated)
/* Deprecated:
   this doesn't parse the JSON on every turn,
   just calls the already built function */
cachedFunction();
ready
Tuenti implementation
tuenti_decode(myjson);
ready
Tuenti secure
tuenti_decode(myjson, true);
ready

Revisions

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