Declaring vars once vs every time for functions

Benchmark created on


Setup

var args = [1, 2, 3, 4, 5, 6];
    
    var withoutRedefine = function(){
      // Declare vars once
      var
        a = 1
      , b = 2
      , c = 3000
      , d = 4000000
      , e
      , f
      , g
        // Assuming we actually have some work creating our vars
      , myArgs = args.slice(3, 5).join(" ").split(" ")
      ;
      // Access variables
      if (a < b && b < c && c < d){
        e = f = g = 1;//myArgs[2];
      }
    };
    
    var withRedefine = function(){
      // Declare vars once
      var
        a = 1
      , b = 2
      , c = 3000
      , d = 4000000
      , e
      , f
      , g
      , myArgs = args.slice(3, 5).join(" ").split(" ")
      ;
      // Redefine test
      withRedefine = function(){
        // Access variables
        if (a < b && b < c && c < d){
          e = f = g = 1;//myArgs[2];
        }
      };
      // Call the new test
      withRedefine();
    };

Test runner

Ready to run.

Testing in
TestOps/sec
Without Redefine
withoutRedefine();
ready
With Redefine
withRedefine();
ready

Revisions

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