Skip to content

Instantly share code, notes, and snippets.

@marekventur
Created April 27, 2015 22:00
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 marekventur/455c7bffb00d9759ec7e to your computer and use it in GitHub Desktop.
Save marekventur/455c7bffb00d9759ec7e to your computer and use it in GitHub Desktop.
underscore profiling for _.sample and _.shuffle
var _ = require('./underscore');
var N = 1000000;
var i;
var input = _.range(1000);
console.log("input = _.range(1000);");
var start = Date.now();
for (i=0; i<N; i++) {
_.shuffle(input);
}
console.log("%dx _.shuffle(input): %dms", N, (Date.now() - start));
var start = Date.now();
for (i=0; i<N; i++) {
_.sample(input, 1000);
}
console.log("%dx _.sample(input, 1000): %dms", N, (Date.now() - start));
var start = Date.now();
for (i=0; i<N; i++) {
_.sample(input, 500);
}
console.log("%dx _.sample(input, 500): %dms", N, (Date.now() - start));
var start = Date.now();
for (i=0; i<N; i++) {
_.sample(input, 2);
}
console.log("%dx _.sample(input, 2): %dms", N, (Date.now() - start));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment