Skip to content

Instantly share code, notes, and snippets.

@ayinlaaji
Last active April 26, 2018 12:02
Show Gist options
  • Save ayinlaaji/a706c23667317f9d24d474f155d4285a to your computer and use it in GitHub Desktop.
Save ayinlaaji/a706c23667317f9d24d474f155d4285a to your computer and use it in GitHub Desktop.
Slicing arguments #jsbench #jsperf (http://jsbench.github.io/#a706c23667317f9d24d474f155d4285a) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Slicing arguments #jsbench #jsperf</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
<h2><code>cmd + alt + j</code> or <code>ctrl + alt + j</code></h2>
</body>
</html>
"use strict";
(function (factory) {
if (typeof Benchmark !== "undefined") {
factory(Benchmark);
} else {
factory(require("benchmark"));
}
})(function (Benchmark) {
var suite = new Benchmark.Suite;
suite.add("Using Arrays", function () {
//Using Arrays
function x1 () {
return Array.prototype.slice.call(arguments, 0);
}
var xr1 = x1();
});
suite.add("Using literals", function () {
//Using literals
function x2 () {
return [].slice.call(arguments, 0);
}
var xr2 = x2();
});
suite.on("cycle", function (evt) {
console.log(" - " + evt.target);
});
suite.on("complete", function (evt) {
console.log(new Array(30).join("-"));
var results = evt.currentTarget.sort(function (a, b) {
return b.hz - a.hz;
});
results.forEach(function (item) {
console.log((idx + 1) + ". " + item);
});
});
console.log("Slicing arguments #jsbench #jsperf");
console.log(new Array(30).join("-"));
suite.run();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment