short for vs unrolled if
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var arrays = [
[{
id: 2,
name: "banana",
x: 10
}, {
id: 4,
name: "apple",
x: 1,
y: 1
}, {
id: 1,
name: "squash",
x: 10
}],
[{
id: 4,
name: "apple",
x: 1,
y: 1
}, {
id: 3,
name: "grape",
x: 10,
y: 1
}],
[{
id: 2,
name: "banana",
x: 10
}],
[],
[],
[{
id: 4,
name: "apple",
x: 1,
y: 1
}, {
id: 3,
name: "grape",
x: 10,
y: 1
}],
[{
id: 2,
name: "banana",
x: 10
}],
];
var alen = arrays.length;
var i = 0;
function get_array() {
if (i == alen) {
i = 0;
}
return arrays[i++];
}
function do_something(array) {
if (array.id > 2 && array.x !== undefined && array.y !== undefined) {
var a = array.x * array.y;
}
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
loop |
|
pending… |
unrolled if |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments