Variables caching (v2)

Revision 2 of this benchmark created by Pomax on


Description

see comment

Setup

// cache them as globals!
    
        var str = 'Some string',
            num = 5 * 34,
            arr = [1,2,3,4],
            job = function () {
                // do something;
            };
    
        var initials = {
            str: str,
            num: num,
            arr: arr,
            job: job
        };
    
    function bottleneck1 () {
    
        var str = 'Some string',
            num = 5 * 34,
            arr = [1,2,3,4],
            job = function () {
                // do something;
            };
    
            job(str, num, arr);
    }
    
    function bottleneck1b() {
        var str = initials.str,
            num = initials.num,
            arr = initials.arr.slice(),
            job = initials.job;
    
        job(str,num,arr);
    }
    
    function bottleneck2 () {
    
        var arr = [1,2,3,4],
            num = 5 * 34,
            job = function () {
                // do something;
            };
    
            job(str, num, arr);
    }
    
    
    
    function bottleneck3 () {
    
        var str = 'Some string',
            num = 5 * 34,
            job = function () {
                // do something;
            };
    
            job(str, num, arr);
    }
    
    function bottleneck4 () {
    
        var str = 'Some string',
            arr = [1,2,3,4],
            job = function () {
                // do something;
            };
    
            job(str, num, arr);
    }
    
    
    function bottleneck5 () {
    
        var str = 'Some string',
            arr = [1,2,3,4],
            num = 5 * 34;
     
            job(str, num, arr);
    }
    
    
    function bottleneck6 () {
    
            job(str, num, arr);
    }

Test runner

Ready to run.

Testing in
TestOps/sec
no cache
bottleneck1();
ready
cache string
bottleneck2();
ready
cache number
bottleneck3();
ready
cache array
bottleneck4();
ready
cache function
bottleneck5();
ready
cache everything
bottleneck6();
ready
Test 1b
bottleneck1b();
ready

Revisions

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