Skip to content

Instantly share code, notes, and snippets.

@JobLeonard
Last active November 29, 2023 09:36
Show Gist options
  • Save JobLeonard/00e164b878d3c009649d4f8a9de6e7f6 to your computer and use it in GitHub Desktop.
Save JobLeonard/00e164b878d3c009649d4f8a9de6e7f6 to your computer and use it in GitHub Desktop.
parseint
{"title":"parseint","initialization":"// Does https://www.slideshare.net/madrobby/extreme-javascript-performance's advice hold up?\n// Answer: nope\nconst numberstrings = [];\nfor (let i = 0; i < 10000; i++) {\n numberstrings[i] = \"\";\n}\nconst output = new Uint32Array(numberstrings.length);","setup":"for (let i = 0; i < 10000; i++) {\n numberstrings[i] = (Math.random() * 0x100000000 | 0) + \"\";\n}\n","tests":[{"name":"parseInt(intString)","code":"for (let i = 0; i < numberstrings.length; i++) {\n output[i] = parseInt(numberstrings[i]);\n}","results":{"aborted":false,"count":119,"cycles":4,"hz":1522.4183545162634,"stats":{"moe":0.000009669273334635679,"rme":1.4720679199484035,"sem":0.000004933302721752898,"deviation":0.00003915687643186873,"mean":0.0006568496740948333,"variance":1.533260971900637e-9,"numSamples":63},"times":{"cycle":0.07816511121728516,"elapsed":5.954,"period":0.0006568496740948333,"timeStamp":1701250488382}},"platforms":{"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0":{"aborted":false,"count":157,"cycles":7,"hz":2039.188564963073,"stats":{"moe":0.000002020093305144737,"rme":0.41193511680096073,"sem":0.0000010306598495636412,"deviation":0.000008309445358004684,"mean":0.0004903911375248952,"variance":6.90468821576656e-11,"numSamples":65},"times":{"cycle":0.07699140859140854,"elapsed":6.205,"period":0.0004903911375248952,"timeStamp":1701250425765}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36":{"aborted":false,"count":119,"cycles":4,"hz":1522.4183545162634,"stats":{"moe":0.000009669273334635679,"rme":1.4720679199484035,"sem":0.000004933302721752898,"deviation":0.00003915687643186873,"mean":0.0006568496740948333,"variance":1.533260971900637e-9,"numSamples":63},"times":{"cycle":0.07816511121728516,"elapsed":5.954,"period":0.0006568496740948333,"timeStamp":1701250488382}}}},{"name":"~~(1 * intString)","code":"for (let i = 0; i < numberstrings.length; i++) {\n output[i] = ~~(1 * numberstrings[i]);\n}","results":{"aborted":false,"count":118,"cycles":5,"hz":1508.4403051691766,"stats":{"moe":0.000006424221362142408,"rme":0.9690554431984436,"sem":0.000003277663960276739,"deviation":0.00002622131168221391,"mean":0.0006629364095968297,"variance":6.875571863358078e-10,"numSamples":64},"times":{"cycle":0.0782264963324259,"elapsed":6.083,"period":0.0006629364095968297,"timeStamp":1701250494341}},"platforms":{"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:120.0) Gecko/20100101 Firefox/120.0":{"aborted":false,"count":132,"cycles":4,"hz":1691.6695299451437,"stats":{"moe":0.000004374489808958788,"rme":0.7400191118871133,"sem":0.000002231882555591218,"deviation":0.000017855060444729745,"mean":0.0005911320043888403,"variance":3.1880318348495274e-10,"numSamples":64},"times":{"cycle":0.07802942457932692,"elapsed":6.005,"period":0.0005911320043888403,"timeStamp":1701250431975}},"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36":{"aborted":false,"count":118,"cycles":5,"hz":1508.4403051691766,"stats":{"moe":0.000006424221362142408,"rme":0.9690554431984436,"sem":0.000003277663960276739,"deviation":0.00002622131168221391,"mean":0.0006629364095968297,"variance":6.875571863358078e-10,"numSamples":64},"times":{"cycle":0.0782264963324259,"elapsed":6.083,"period":0.0006629364095968297,"timeStamp":1701250494341}}}}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment