Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
test-substring v index
var alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
var alphabetLength = alphabet.length;
var i, rnd, trips = 1000000000;
var d1 = new Date();
console.log(d1);
for (i = 0; i < trips; i++) {
rnd = Math.floor(Math.random() * alphabetLength);
alphabet.substring(rnd, rnd + 1);
}
var d2 = new Date();
console.log(d2);
var d3 = new Date();
console.log(d3);
for (i = 0; i < trips; i++) {
rnd = Math.floor(Math.random() * alphabetLength);
alphabet[rnd];
}
var d4 = new Date();
console.log(d4);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment