Created
January 11, 2019 21:53
-
-
Save isaaclyman/352bf9aac5fd4cf0019fb4498ccbf850 to your computer and use it in GitHub Desktop.
A function to test how long it takes to do 15,000 function calls and array assignments by index in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function testSpeed() { | |
const stack = []; | |
function assignValue(index) { | |
stack[index] = 'bob ' + index; | |
} | |
const t0 = performance.now() | |
for (let ix = 0; ix < 15000; ix++) { | |
assignValue(ix); | |
} | |
const t1 = performance.now() | |
return [stack, t1 - t0]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested on Chrome 71 and a Dell Precision 5510 (i7 dual-core CPU) = 4ms.