{"id":20473519,"url":"https://github.com/xpl/what-code-is-faster","last_synced_at":"2025-04-13T11:28:19.141Z","repository":{"id":149363331,"uuid":"319215051","full_name":"xpl/what-code-is-faster","owner":"xpl","description":"A browser-based tool for speedy and correct JS performance comparisons!","archived":false,"fork":false,"pushed_at":"2024-09-13T02:14:19.000Z","size":2504,"stargazers_count":25,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-27T02:39:21.551Z","etag":null,"topics":["benchmark","benchmark-scripts","benchmarking","comparison-benchmarks","comparison-tool","javascript","performance","performance-benchmarking","tool"],"latest_commit_sha":null,"homepage":"https://xpl.github.io/what-code-is-faster/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xpl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-07T05:37:32.000Z","updated_at":"2024-09-13T02:14:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"ebec3d64-acc1-4d72-95e7-9d152a392153","html_url":"https://github.com/xpl/what-code-is-faster","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/xpl%2Fwhat-code-is-faster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpl%2Fwhat-code-is-faster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpl%2Fwhat-code-is-faster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xpl%2Fwhat-code-is-faster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xpl","download_url":"https://codeload.github.com/xpl/what-code-is-faster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248705108,"owners_count":21148480,"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":["benchmark","benchmark-scripts","benchmarking","comparison-benchmarks","comparison-tool","javascript","performance","performance-benchmarking","tool"],"created_at":"2024-11-15T14:25:44.302Z","updated_at":"2025-04-13T11:28:19.111Z","avatar_url":"https://github.com/xpl.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# \u003ca href=\"https://xpl.github.io/what-code-is-faster/\"\u003eWhat Code Is Faster?\u003c/a\u003e\n\n**A browser-based tool for speedy and correct JS performance comparisons!**\n\n- Minimalistic UI\n- Code editor with IntelliSense\n- All state is saved to URL - copy it and share with friends in no time!\n- Automatically determines the number of iterations needed for a proper measurement — no hard-coding!\n- Prevents dead code elimination and compile-time eval. optimizations from ruining your test!\n- Verifies correctness (functions must compute the same value, be deterministic, depend on their inputs)\n- Warms up functions before measuring (to give time for JIT to compile \u0026 optimize them)\n\n\u003ca href=\"https://xpl.github.io/what-code-is-faster/\"\u003e\u003cimg width=\"100%\" alt=\"Try it online!\" src=\"https://user-images.githubusercontent.com/1707/101344538-af2ace00-3896-11eb-808c-824a228dc50f.png\"\u003e\u003c/a\u003e\n\n## How Does It Work?\n\nBenchmarked functions are written as _reducers_, i.e. taking a previous value and returning some other value. The runtime executes your functions in a tight loop against some random initial value, saving the final value to a global variable (thus producing a _side effect_), so that no smart compiler could optimize out our computation!\n\nSo you must also provide a random initial value (not [something like that](https://xkcd.com/221/)) and ensure that your reducers follow some simple rules. **Those rules are programmatically enforced** — so you won't shoot yourself in the foot. Check the examples to get a sense of how to write a benchmark.\n\nThe rules:\n\n1. The result of a function must depend on its input — and only on its input! You cannot return the same value again and again, or return some random values — there should be some genuine non-throwable computation on a passed input.\n\n2. Given the same input, the output of the functions must be all the same. The comparison should be fair — we want to compare different implementations of exactly the same thing!\n\n## Examples\n\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqdTj0PgjAQ3fsr3iZNCFHCyk9wdSEMJxRoLAdpC9EY%2FrtQjHFw8oZL3se9d1fFVdeTvUUHspYeGCfXYXYJyDndMvwAQ85Dc63uhxjNxJXXA6%2BE9prMhcykIomnAKzyk2UUZ%2FJdYonroY9kKZY4qFtyNFo172ZANwg4MYpb3yHPc5yO68hPUhmMwRTOs1QG5q1vwoqXeF37v%2F8XFF%2FOEjmy9FeTWKR4AT%2BbX6E%3D\"\u003eArray push vs. assign to last index\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNp9UctOwzAQvPcrRlxq09CHVPVQKQe4cYBbuVQV2rRWY5Fsiu0UFei%2FY8eJRKpCZEX2rGd2Z5wp3uYlmTcxzPRes4NYzO8y7SSOdgyuy0wZCM1bo0rFTg4TfA0AzdppKl6oqJUVssGAbcXWwSq1Q4rZtPkwgngil48N8a4q%2Fd3bpiTxjWnDMsrVhlsJIM6xxIPeP7ITQU0mvdpi3lXHZFceePZDJz2CTDCZIPc1i%2BrgdKk%2FvQ%2BXk4P2yyK6vJB9JWOWYPURtFYNdG8MncT6t%2FYmilNhK3DlQIwbMl7NkNHFKaj5fNxNKx4zXDaxRB9n%2Fz%2BHrXqvqRCUIOsSbLNo25FEmnaHTAba4BwfII4sDkYdL7gB8qHPuOvSubt2%2Bc8Ye1Akjq6VZizlZaMQY69Z2K%2BnG4zSOFZv1o4dc%2FrPUfQvBz9PYs0i\"\u003eBigInt (64-bit) vs. number (increment)\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNq1jsEKwjAQRO%2F5irlIE41CzyJ%2BgVfvmxppsN3UbSqI9N%2BtqUh%2FwMvC7pudGee5qluSmy5OlOpd%2FexiQhTkrb9LOhYW14GrFCIjcEiBmjM1g9cGLwWIT4PwrBfiS2y1UaPNLLvpTvxj1gJV5D6BcEA%2BY4PSYIVyAd0PbpdwmTP7koUz%2BwmOdhqfrn%2BIyra0pundrb9xajTqDeIvWf8%3D\"\u003eMath.hypot or Math.sqrt?\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqVjz0OwjAMhfecwgtqIiokTsCC2FjZTZrSiNRB%2BUFFKHcnSaVCR5Yo9nvPn91HkkFbgj4SnwS8wakQHcEZw7Dzuja3cyWtL1Vi7KpIDiO6O2%2BOFoyVaMqAeVKnpEGH5e8hZwIgvcKg6XZo2q9Nkw4azQVNVDyDGazQDqmzIxcstVVTU1CO0PCHU8%2FZvgTK7qUNG9iLLKQ2P3WrlXtBV%2Bn0x8E%2FrCW7ArIk2AdkO2vC\"\u003eDo local function declarations affect performance?\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqNj70OwjAMhPc8hRfURFRIzAixIDZW9hBSGpE6yElQEcq7k7Si%2FEwsluw732c3EVUwDqGJyHsBDyAdIiHsZWgX3gzD%2Bdgp50uXGDtqVG0n6cKrrQNlnY%2BkPWRDAIn30Bo8b6q6hI7pBk0w0h6kjZpnCoMvDkk8uY4LlupB033QhNLyK%2BnbaJ8WyqFlDDNYiiykOhfr1I97Qg%2FSLi%2BV55TDfGIPa3hFrP55%2BAP%2FjitslgR7AtISZ6c%3D\"\u003eDo closures affect performance (vs. free functions)?\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqVj7GOwkAMRPv9iunYFRE6WlCQ7gOokOj3gkNWBC9yNrmcUP6ddUiNdC5ceMZvbC%2BCEt8i%2Fm9TS7zbJ1ria2p22H7lwlTAjgWCQ3nI3XSU8gLTL06UrBdxxvwQV83dy82u6ihoY3wgDiRqwdC98asCdc9VCpEROKTg27Nve7IOTwMIpV4YR5%2BajXi%2B5FOcyeGqKWtm2IfQ8PYDGmWryF3CiFhDb1kkQI1Ylxj382Ca%2B5Khmo6nYmHrJ5%2FI%2Bed%2Fks3kzAvj%2BGda\"\u003eFor..of loop over Set vs. Array\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNptkEFPhDAUhO%2F9FXPbVgnBqwaTPexx482L8VCwCAu0pC2IQf67r2XNhsQeepg3871p28khx9Fa%2BZ1W1vR8Qaf0p68f8ZDRwZqAzwkagfwZb%2FwsfZ1aqT%2FIKnC3mbJM4AcZud4FM8WFiC%2FFRZU%2BIk%2Fa20Y53k5OsF4ONNXqC2c5bBIrlC7rXtqWH66xSXajcqBu5EorY0%2ByrA8JqlGXvjEajW58I7vX4KMeCwOs8qPV2BVk1D7MTMRGt%2BODVdMWAQgNXhrtPGaYCrv9nGLizwmEHO5zzE9RWON93RpmQV4TFqGh725Rf3sHn8NXLjceVvEvi5H%2BC%2BzZfuY%3D\"\u003eFor..of loop over Object.values vs. Map.forEach (large integer keys)\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNp1kD9PwzAQxfd8ittqo8iFsiEViYGBgTIgsUQRclw3cZ2cK9sBqpLvzuVPq1aiHiL53vu9vLNyGCKsYAl3t3QSNdy9xLVrXnCtf0hhHJaPwF5lrMSo0OQGVhx%2B4UhYvQ9kffJe7sXGk%2BUAtcYyVg%2BU3qVTyEWGiO49eoMlu19wEWqjNFtwfpb4IetW97n9RTRyx2yfktl0mGRnPRnP8yNKRmJQf9P%2FCDkFHXVXbEl%2FK7ZaxaHsM1IPHS6sSaFRVY30ls0oBr6CmBBgtXO23fFZCpsWVTQOwaCJRtYDTbseEgCvY%2Bvxv6YJPUjvoKKfYxazI3OiSBKljv18Pp%2BGYdiJ8sjYpfShRa7xJGU2v8ImHU%2F%2BAAGxpI8%3D\"\u003eMap vs. Object (lookup)\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqtkD9TgzAYxvd8imfxSCzHgSN3yOnmoIvn5DmkECRXSGoaPGrlu5uArdDFpev7Pn%2Fe91dotbPgxvD9s%2FwSyJDEcUyKcWy4KnX71LVrYXZudedlUWV0Sw9ohHq3dTrzDiEkslvca90IrqjEFW4YW4S9qFJUUonS5y3yo5Zvae%2F9PXJ0Rx1S9Ozsnqb5x62cZDKStVBF3XKzoYE3QptZNhUfHW%2Bk3aOoRbFheRCi6lRhpVaQSlrJmwen7inDgQBG2M4o0Edu62jqd5vrkVkcM3wjJo6ClwanloBujfgcY6YUYHrHwcLfDiskzBE78RyVv43n8F7lG7Ism72Su7gUcpU42xD6AzyEy3WP1I%2B1I99FIxkY%2BQHRKbx2\"\u003eNull or undefined? (equality check)\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqNkNFKwzAUhu%2FzFP%2BNLHEhdF4qE%2FYA9kq8GUNO03QNpmlJ08GYfXfTVhFFZBc5OQlfPv6TavA62taDyvK5DsbkQ1OY0HOSKCS0wIUBwcQhJAZrFGnpBzYy3fo%2BIscWmyz7PFEIdE43u2lXVWgbfoEz%2Fhjr%2B4SOEvxVwgpsH7G3qUuyzbLdHQRjhfG6bii88VXfBUMlTr2CJufmhrrOnVcS1Vdo62205F7IDYb%2FiMqfKNYqkC9TBoFb5ALvyFiKMFGLnad6Wp59z%2FjrH5RS81T7iT0I3CBP%2BChTmXJdoVAz5wfnJP6xzcNdo1vAxfeXjI2CfQDZNZNS\"\u003eArguments passing: spread vs. call() vs. apply()\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqFjsEKgzAQRO%2F5iiUUklCR9ir0BwptD4VeRDBqxNAYJUYvIf%2FeqNBaKPS07M7OmymELpuWmycl5%2FvtGvfcDAKmAcTEFYmgHnVpZadBamklVw%2BuRkEZOARghB2Nhgu3TWy4rrqWMuSjRdvQCO2NmFbL2%2FSRae5w3XU4cbjgBifpzs3%2FsIejz7zPWUqCTLKUBDmMQxY4Ppozlo5fdCUsLNRqWecHmq8HOMGfoG2%2F1fMzGnmGXucCYXA%3D\"\u003eJSON.parse() vs. eval()\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNqlkl1LwzAUhu%2F7K86daTer68QLZYIgghcOL8SbUSRpOxfckpmmfuD23z1JmyZzIIq7GGfn43nfc7JCilrDFCYwOjaf86iwGUVFKVc3oqzesUZimFwAuaV6kbYVzCQwjWEDONLNvFaFlqrG%2Fkul6Ec6V9j3uazEk16coUYC4%2B2wY%2B2g4h5BlcLxWZqmHSx3hvTHuiqxJqo3uF5Kqk9PrArpGj1jTbmBEG6FZtzoouz0kB%2BOjOsxMiNWiWKxouqZHFgMvNZwbyTaX1dSw52SZVPogyHMG1FoLgVwwTWnywe6bCrc4zMCaDU5CgYnI%2BgGQFW6UcL6QTPnES5vJqhReCylJjM6BJa3HEcSFFH2OvWL0gSbZzRH110waIPBKE9c0Ocyl8tyq98j2R6SOSRz48whmUcyh2R7SPMSFBmChWlcylx%2Bx7RZcGB7SO846SW%2F1TJf%2B6ZYyNqwjcIRiLYSHpjYBvOf3Bzbwe0Qv%2By%2F5re3ts2t8T4cuNCcx4dBPvP5n%2B%2FedjGPZx7DPJ6FeObxf3yDvWWCdwj2SAIDe%2FUsrP%2F7PaJt%2FAXzs1VV\"\u003eArray vs TypedArray Dot Product\u003c/a\u003e\n- \u003ca href=\"https://xpl.github.io/what-code-is-faster/?code=eNq1kTFPwzAQhXf%2FiregxjSKUsZWoWoHJAYmRsRgHJdYbc%2FIcaGl5L9zdlVI1Q4sLNbJfvfed2ftqA1Q3qvdo%2F00qDAqy1IIvVJtizvnsBfAlu8fVGgKr6h260xORHfUzJWfq9b8RQezDYbq057d5Z7EdbhiinZGNTe1rJ1F1mLhWbrHytBraMYJGl0Oi%2BqWjyvcYAoyH3GCTGKcajbIpBTixZBu1sovs4HlFEXauAWcRwr1Gx1i3Ri9nA5yLDakg3UESzZYtbqn2mzZM7J7EzaekJ3w4zrhlKXEF0rBVFHaixpkb968J5%2BDDQ7JkR6%2FbxhiJHmUn89JymPk2Wqe7HPRH6Cqqji95EVYXoAdjiZs0OWRpaf7Nxj0dnuBQ3RSfAMoXsbB\"\u003einstanceof or constructor check?\u003c/a\u003e\n\n- \u003ci\u003e..Add your own? Pull Requests are welcome!\u003c/i\u003e\n\n## Extended Configuration\n\nIn case you test functions operate on differently typed inputs, you might need to provide distinct initial values and provide a customized comparison function, otherwise it won't pass the soundness check. Here is an example:\n\n```js\nbenchmark('bigint vs number (addition)', {\n  initialValues() {\n    const seed = 1000000 + (Math.random() * 1000) | 0\n    return {\n      bigint: BigInt(seed),\n      number: seed,\n    }\n  },\n  equal(a, b) {\n    return BigInt(a) === BigInt(b)\n  }\n}, {\n  bigint(prev) {\n    return prev + 1n\n  },\n  number(prev) {\n    return prev + 1\n  }\n})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpl%2Fwhat-code-is-faster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxpl%2Fwhat-code-is-faster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxpl%2Fwhat-code-is-faster/lists"}