{"id":13725113,"url":"https://github.com/GoogleChromeLabs/json-parse-benchmark","last_synced_at":"2025-05-07T19:32:51.967Z","repository":{"id":54361339,"uuid":"196946863","full_name":"GoogleChromeLabs/json-parse-benchmark","owner":"GoogleChromeLabs","description":"Benchmark comparing JSON.parse vs. equivalent JavaScript literals across JavaScript engines.","archived":false,"fork":false,"pushed_at":"2023-08-11T11:05:59.000Z","size":16,"stargazers_count":122,"open_issues_count":2,"forks_count":11,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-08-04T01:27:05.372Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://v8.dev/blog/cost-of-javascript-2019#json","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleChromeLabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-07-15T07:26:38.000Z","updated_at":"2024-07-26T03:19:50.000Z","dependencies_parsed_at":"2024-01-10T12:01:32.673Z","dependency_job_id":"2fe006a7-f9a3-4f6d-bf8e-a2dfea0cd0be","html_url":"https://github.com/GoogleChromeLabs/json-parse-benchmark","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fjson-parse-benchmark","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fjson-parse-benchmark/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fjson-parse-benchmark/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChromeLabs%2Fjson-parse-benchmark/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleChromeLabs","download_url":"https://codeload.github.com/GoogleChromeLabs/json-parse-benchmark/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224645221,"owners_count":17346100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T01:02:13.363Z","updated_at":"2024-11-14T15:30:45.302Z","avatar_url":"https://github.com/GoogleChromeLabs.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# `JSON.parse` benchmark\n\nSee [the cost of parsing JSON](https://v8.dev/blog/cost-of-javascript-2019#json).\n\n## Instructions\n\nClone this repository, and then run these commands:\n\n```bash\nnpm install\nexport PATH=\"${HOME}/.jsvu/bin:${PATH}\"\nnpm run bench\n```\n\n## Analysis\n\n[`JetStream2/SeaMonster/inspector-json-payload.js`](https://raw.githubusercontent.com/WebKit/webkit/ffdd2799d3237993354978b9d0cdd1d248fe3787/PerformanceTests/JetStream2/SeaMonster/inspector-json-payload.js) contains a 7.33-MB JavaScript array literal containing 846 object literals. This entire array literal can be [serialized to JSON](https://github.com/GoogleChromeLabs/json-parse-benchmark/blob/c0dec965dfbb6e30f077974ce172296f1f90d5da/build.js#L18) and [turned into a 8.2-MB JavaScript string literal](https://github.com/GoogleChromeLabs/json-parse-benchmark/blob/c0dec965dfbb6e30f077974ce172296f1f90d5da/build.js#L19), which can be [passed to `JSON.parse()`](https://github.com/GoogleChromeLabs/json-parse-benchmark/blob/c0dec965dfbb6e30f077974ce172296f1f90d5da/build.js#L22) to produce an equivalent array.\n\nThis repository tests each approach in 100 different contexts in the dumbest possible way, i.e. by simply invoking `d8` a 100 times per script. That is, we perform 100 cold loads, and measure everything (parsing, compilation, and execution) until the program halts.\n\nOn my workstation (HP Z840 with 2 × 14-core Intel Xeon E5-2690 v4 processors @ 2.6GHz, 35MB Cache + 128GB DDR4 2400MHz RAM), I got the following results:\n\n|                        | JS literal | `JSON.parse` | Speed-up |\n| ---------------------- | ---------: | -----------: | -------: |\n| V8 v7.5                |   23.765 s |     15.766 s |     1.5× |\n| V8 v7.6                |   23.639 s |     14.102 s |     1.7× |\n| V8 v7.7                |   23.489 s |     13.886 s |     1.7× |\n| Chakra v1.11.10.0      |   24.999 s |     16.547 s |     1.5× |\n| JavaScriptCore v246878 |   28.503 s |     14.315 s |     2.0× |\n| SpiderMonkey v68.0b13  |   25.554 s |     21.174 s |     1.2× |\n\nFor V8 specifically, you can get detailed metrics for a single run by using `--runtime-call-stats`:\n\n```\n$ v8 --runtime-call-stats out/js.js | grep Parse\n                                      ParseProgram    124.33ms  47.00%         1   0.00%\n\n$ v8 --runtime-call-stats out/json.js | grep Parse\n                                         JsonParse     47.67ms  28.29%         1   0.07%\n                                      ParseProgram     43.17ms  25.62%         1   0.07%\n```\n\n## Licensing\n\nThe source files in this repository are released under the Apache 2.0 license, as detailed in the LICENSE file.\n\nThe scripts in this repository dynamically download [`JetStream2/SeaMonster/inspector-json-payload.js`](https://raw.githubusercontent.com/WebKit/WebKit/ab7171c1d63acb8c77216b5a11f98323b56b998b/PerformanceTests/JetStream2/SeaMonster/inspector-json-payload.js), which has its own license:\n\n```\n/*\n * Copyright (C) 2018 Apple Inc. All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions\n * are met:\n * 1. Redistributions of source code must retain the above copyright\n *    notice, this list of conditions and the following disclaimer.\n * 2. Redistributions in binary form must reproduce the above copyright\n *    notice, this list of conditions and the following disclaimer in the\n *    documentation and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,\n * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\n * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS\n * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\n * THE POSSIBILITY OF SUCH DAMAGE.\n*/\n```\n\nThis license also applies to the generated `*.js` files produced by the scripts in this repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChromeLabs%2Fjson-parse-benchmark","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleChromeLabs%2Fjson-parse-benchmark","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChromeLabs%2Fjson-parse-benchmark/lists"}