long array data access

Benchmark created by Paweł Sierszeń on


Setup

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];
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Short
var i;
for (i = 0; i < 360; i++) {
    test_short(i);
}
ready
Long
var i;
for (i = 0; i < 360; i++) {
    test_long(i);
}
ready
Short (no function call)
var i;
for (i = 0; i < 360; i++) {
    results_short[Math.floor(i/22.5)];
}
ready
Long (no function call)
var i;
for (i = 0; i < 360; i++) {
    results_long[i]
}
ready
Long (no function call) with floor
var i;
for (i = 0; i < 360; i++) {
    results_long[Math.floor(i)]
}
ready
experimental
var i;
for (i = 0; i < 360; i++) {
    results_long[Math.floor(i/22.5)]
}
ready
experimental - end of array
var i;
for (i = 0; i < 360; i++) {
    results_long[(i >> 1) + 180]
}
ready
experimental - beginning of array
var i;
for (i = 0; i < 360; i++) {
    results_long[(i >> 1)]
}
ready
experimental - every second element
var i;
for (i = 0; i < 360; i++) {
    results_long[(i << 1) % 360]
}
ready
experimental - random element
var i;
for (i = 0; i < 360; i++) {
    results_long[Math.floor(Math.random()*360)]
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Paweł Sierszeń on