long array data access
JavaScript performance comparison
Preparation code
<script>
Benchmark.prototype.setup = function() {
var results_short = [
'NORTH',
'NORTHEAST', 'NORTHEAST',
'EAST', 'EAST',
'SOUTHEAST', 'SOUTHEAST',
'SOUTH', 'SOUTH',
'SOUTHWEST', 'SOUTHWEST',
'WEST', 'WEST',
'NORTHWEST', 'NORTHWEST',
'NORTH', 'NORTH'];
function test_short(angle) {
return results_short[Math.floor(angle/22.5)];
}
var results_long = [];
for (var i = 0; i < 360; i++) {
results_long[i] = results_short[Math.floor(i/22.5)];
}
function test_long(angle) {
return results_long[angle];
}
};
</script>
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
Short |
|
pending… |
Long |
|
pending… |
Short (no function call) |
|
pending… |
Long (no function call) |
|
pending… |
Long (no function call) with floor |
|
pending… |
experimental |
|
pending… |
experimental - end of array |
|
pending… |
experimental - beginning of array |
|
pending… |
experimental - every second element |
|
pending… |
experimental - random element |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments