To recap;
Whilst comenting on a question, I asked " Does the length and complexity of variable names make any difference to a program compiling or a function running. "
Jan Simon kindly replyed " A school boy solution for the question about the complexity of symbols: Try it. Simply measure the time using TIC/TOC. But the question is too important to be hidden in the comments of another question. "
Well I did, I ran this;
function vShortOut = vShort(vSin)
tic
x = 1;
while x < 100000000
ab = vSin;
abyz = ab*ab;
abyz = abyz^10;
vShortOut = abyz;
x = x + 1;
end
toc
I also created the corresponding vLong, where ab was the complete alphabet and abyz was double alphabet. My result are;
while x < 1000000
vShort(2) - Elapsed time is 0.022960 seconds.
vLong(2) - Elapsed time is 0.027503 seconds.
vLong(2) - Elapsed time is 0.026545 seconds.
while x < 10000000
vShort(2) - Elapsed time is 2.148615 seconds.
vShort(2) - Elapsed time is 2.122362 seconds.
vShort(2) - Elapsed time is 2.115379 seconds.
vLong(2) - Elapsed time is 2.089561 seconds.
vLong(2) - Elapsed time is 2.074754 seconds.
vLong(2) - Elapsed time is 2.060859 seconds.
while x < 100000000
vShort(2) - Elapsed time is 20.904584 seconds.
vShort(2) - Elapsed time is 21.067507 seconds.
vShort(2) - Elapsed time is 20.979640 seconds.
vLong(2) - Elapsed time is 21.135573 seconds.
vLong(2) - Elapsed time is 21.064247 seconds.
vLong(2) - Elapsed time is 21.089929 seconds.
My conclusion is, that on my machine (year old quad core) running this function and variable length makes little or no difference. I noticed that watching processor performance in task manager when the while loop was in the 100's and 1000's, a system process or mouse movement could skew my ans sufficiently to make this test incomparable.
So my question still stands because logic tells me that when running an un-compiled function like this it has to make a difference, the processor has to read and find the variable. The longer the variable the more the processor has to read. Now for a compiled language like c/c++, that recently started learning also, the variable length should only effect (in theory/logic) the compile time not run time. I assume/hope that the compiler will reduce variable names to a short symbol or even memory pointers.
I asked this because I was being told off about ambiguous variable names and it got me thinking.
Please correct me where I am wrong.
Regards,
AD