JSON Parsing (v5)

Revision 5 of this benchmark created 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));
  
  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 Parse
(new Function('return ' + myjson))();
ready
Cached 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.