Skip to content

Instantly share code, notes, and snippets.

@mraleph
Created November 29, 2016 06:40
Show Gist options
  • Select an option

  • Save mraleph/af62501f3b52d581751e88f11edcf3cb to your computer and use it in GitHub Desktop.

Select an option

Save mraleph/af62501f3b52d581751e88f11edcf3cb to your computer and use it in GitHub Desktop.
var mode = arguments[0]
//var mode = "es5";
function es6(a, b, c) {
return Math.max(...[a, b, c]);
}
function es5(a, b, c) {
return Math.max.apply(null, [a, b, c]);
}
function benchmark(f) {
var start = Date.now();
for (var i = 0; i < 1000000; i++) {
f(1, 2, 3);
}
var end = Date.now();
return (end - start);
}
var f = (function () {return this})()[mode];
print('benchmarking...');
print(f);
benchmark(f);
benchmark(f);
benchmark(f);
print(benchmark(f) + ' ms per 1000000 iterations');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment