Accessing Global Variable

Benchmark created by Deekshith Allamaneni on


Description

Performance impact of using global variables

Setup

var a = 3;
    
    function sumGlob(b) {
        for(var i = 0; i<1000; i++){
            b=a+b;
        }
        return b;
    }
    
    function sumLoc(b) {
        for(var i = 0; i<1000; i++){
            b=a+b;
        }
        return b;
    }
    
    
    function sumNo(b) {
        for(var i = 0; i<1000; i++){
            b=3+b;
        }
        return b;
    }

Test runner

Ready to run.

Testing in
TestOps/sec
Using global
sumGlob(4);
ready
Using local
sumLoc(4);
ready
No variable
sumNo(4);
ready

Revisions

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

  • Revision 1: published by Deekshith Allamaneni on