Skip to content

Instantly share code, notes, and snippets.

@chilts
Created November 30, 2011 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilts/1408627 to your computer and use it in GitHub Desktop.
Save chilts/1408627 to your computer and use it in GitHub Desktop.
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