Skip to content

Instantly share code, notes, and snippets.

@isaaclyman
Created January 11, 2019 21:53
Show Gist options
  • Save isaaclyman/352bf9aac5fd4cf0019fb4498ccbf850 to your computer and use it in GitHub Desktop.
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
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];
}
@isaaclyman
Copy link
Author

Tested on Chrome 71 and a Dell Precision 5510 (i7 dual-core CPU) = 4ms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment