JSON.parse() vs eval() - naive

JavaScript performance comparison

Test case created by Tom Dale

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  let json = '{"symbols":["component"],"statements":[[5,"glimmer-repl",[],[[],[]],{"statements":[[0,"\\n"],[4,"if",[[19,0,["isLoaded"]]],null,{"statements":[[0,"    "],[6,"div"],[9,"class","pane editor"],[7],[0,"\\n      "],[6,"h1"],[9,"class","title"],[7],[0,"Glimmer Playground"],[8],[0,"\\n"],[4,"each",[[19,0,["components"]]],[["key"],["id"]],{"statements":[[0,"        "],[6,"div"],[9,"class","component"],[7],[0,"\\n          "],[6,"h2"],[9,"class","component-name"],[7],[0,"\\n              "],[6,"span"],[9,"class","bracket"],[7],[0,"<"],[8],[4,"if",[[19,1,["isEditable"]]],null,{"statements":[[5,"editable-title",[],[["@value","@onChange"],[[19,1,["name"]],[25,"action",[[19,0,["componentNameDidChange"]],[19,1,[]]],null]]],{"statements":[],"parameters":[]}]],"parameters":[]},{"statements":[[1,[19,1,["name"]],false]],"parameters":[]}],[6,"span"],[9,"class","bracket"],[7],[0,">"],[8],[0,"\\n"],[4,"if",[[19,1,["isEditable"]]],null,{"statements":[[0,"                "],[5,"remove-button",[],[["@onClick"],[[25,"action",[[19,0,["removeComponent"]],[19,1,[]]],null]]],{"statements":[],"parameters":[]}],[0,"\\n"]],"parameters":[]},null],[0,"          "],[8],[0,"\\n          "],[6,"div"],[9,"class","file template"],[7],[0,"\\n            "],[6,"h3"],[9,"class","file-name"],[7],[0,"template.hbs"],[8],[0,"\\n            "],[5,"code-editor",[],[["@file"],[[19,1,["template"]]]],{"statements":[],"parameters":[]}],[0,"\\n          "],[8],[0,"\\n"],[4,"if",[[19,1,["component"]]],null,{"statements":[[0,"            "],[6,"div"],[9,"class","file implementation"],[7],[0,"\\n              "],[6,"h3"],[9,"class","file-name"],[7],[0,"\\n                component.ts\\n                "],[5,"remove-button",[],[["@onClick"],[[25,"action",[[19,0,["removeComponentImplementation"]],[19,1,[]]],null]]],{"statements":[],"parameters":[]}],[0,"\\n              "],[8],[0,"\\n              "],[5,"code-editor",[],[["@file"],[[19,1,["component"]]]],{"statements":[],"parameters":[]}],[0,"\\n            "],[8],[0,"\\n"]],"parameters":[]},{"statements":[[0,"            "],[6,"div"],[9,"class","file add-implementation"],[7],[0,"\\n              "],[5,"repl-button",[],[["@onClick","@title"],[[25,"action",[[19,0,["addComponentImplementation"]],[19,1,[]]],null],"Add TypeScript"]],{"statements":[],"parameters":[]}],[0,"\\n            "],[8],[0,"\\n"]],"parameters":[]}],[0,"        "],[8],[0,"\\n"]],"parameters":[1]},null],[0,"\\n      "],[5,"repl-button",[],[["@onClick","@title"],[[25,"action",[[19,0,["createNewComponent"]]],null],"Create New Component"]],{"statements":[],"parameters":[]}],[0,"\\n    "],[8],[0,"\\n\\n    "],[6,"div"],[9,"class","pane vm"],[7],[0,"\\n      "],[5,"glimmer-sandbox",[],[["@fs","@onUnknownComponent"],[[18,"fs"],[25,"action",[[19,0,["saveUnknownComponent"]]],null]]],{"statements":[],"parameters":[]}],[0,"\\n    "],[8],[0,"\\n"]],"parameters":[]},{"statements":[[0,"    "],[6,"div"],[9,"class","pane editor"],[7],[0,"\\n      "],[6,"div"],[9,"class","loading"],[7],[0,"\\n        "],[6,"span"],[7],[0,"Loading the Playground..."],[8],[0,"\\n      "],[8],[0,"\\n    "],[8],[0,"\\n    "],[6,"div"],[9,"class","pane vm"],[7],[0,"\\n    "],[8],[0,"\\n"]],"parameters":[]}]],"parameters":[]}],[0,"\\n"]],"hasEval":false}'

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
JSON.parse()
window.parsedJSON = JSON.parse(json);
pending…
eval()
window.parsedJSON = eval('(' + json + ')');
pending…

Revisions

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

0 Comments