function is faster when accessing function variables not global ones?

i have a function FindThings() that compares lots of Vector3’s found with findWithTag to one global var PlayerLocation:Vector3 from the top of the script

it seems that if FindThings() calls PlayerLocation multiple times from the global variables, it goes slower than if PlayerLocation is sent to the function as a function variable:

FindThings(PlayerLocation); 
{
Do various PlayerLocation comparisons;
}

is faster than

var PlayerLocation:Vector3;

FindThings()
{
Do various PlayerLocation comparisons;
}

EDIT: this function is going very slowly, it was even slower when location was a global variable. i have another version of the same function that goes 100 times faster. it’s odd.

function delAdjoining(location: Vector3)//Dell all walls surrounding a space if revisited prior to rebuilding
{
		for (var j:int = 0; j < neighbours.length; j ++)
		{
			if ( neighbours[j] == location )
			{	
				var dwalls = GameObject.FindGameObjectsWithTag ("wall");
				for (var dwall in dwalls)
				{			
					if(dwall.transform.position ==  (location + stp1*.5*sizeMult)){Destroy(dwall);}
					if(dwall.transform.position ==  (location + stp2*.5*sizeMult)){Destroy(dwall);}
					if(dwall.transform.position ==  (location + stp3*.5*sizeMult)){Destroy(dwall);}
					if(dwall.transform.position ==  (location + stp4*.5*sizeMult)){Destroy(dwall);}
					if(dwall.transform.position ==  (location + stp5*.5*sizeMult)){Destroy(dwall);}
					if(dwall.transform.position ==  (location + stp6*.5*sizeMult)){Destroy(dwall);}
            		print("erased adjoining");			
				}
				break;
			}
		}
}

Yes, although the difference is very small. You would generally prefer to keep variables local primarily because of better script organization; the speed benefit is just a bonus since it will not be measurable in most cases.

That really slow code you posted as your edit is slow because you’re doing
GameObject.FindGameObjectsWithTag (“wall”); repeatedly.

FindGameObjectWithTag is slow. To get a true sense of the speed gain cache the result of FindGameObjectWithTag in an array.

Move your GameObject.FindGameObjectsWithTag outside the loop, cause it’s slowly.

function delAdjoining(location: Vector3)//Dell all walls surrounding a space if revisited prior to rebuilding
{
       var dwalls = GameObject.FindGameObjectsWithTag ("wall");
       for (var j:int = 0; j < neighbours.length; j ++)
       {
         if ( neighbours[j] == location )
         {    
          for (var dwall in dwalls)
          {      
              if(dwall.transform.position ==  (location + stp1*.5*sizeMult)){Destroy(dwall);}
              if(dwall.transform.position ==  (location + stp2*.5*sizeMult)){Destroy(dwall);}
              if(dwall.transform.position ==  (location + stp3*.5*sizeMult)){Destroy(dwall);}
              if(dwall.transform.position ==  (location + stp4*.5*sizeMult)){Destroy(dwall);}
              if(dwall.transform.position ==  (location + stp5*.5*sizeMult)){Destroy(dwall);}
              if(dwall.transform.position ==  (location + stp6*.5*sizeMult)){Destroy(dwall);}
                   print("erased adjoining");         
          }
          break;
         }
       }
}