variable reference caching

Benchmark created by Jarred Nicholls on


Description

Test the speed of caching nested global variables to local variable references in tight loops.

Preparation HTML

<script>
Some = {
    Deeply: {
        Nested: {
            array: [1, 2, 3, 4, 5]
        }
    }
};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
no cache
for (var i = 0, x; i < Some.Deeply.Nested.array.length; i++) {
    x = Some.Deeply.Nested.array[i];
}
ready
cached var
var arr = Some.Deeply.Nested.array,
    ln = arr.length;
for (var i = 0, x; i < ln; i++) {
    x = arr[i];
}
ready

Revisions

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

  • Revision 1: published by Jarred Nicholls on