Question Relating To Variables -
Karkand - 05.09.2012
I would assume when saving a variable into a file and also reading it, such as:
Код:
VariableNameHere = 3
would be slower to save compared to saving it as:
Where the length in the variable name is shorter, would I be correct?
Re: Question Relating To Variables -
Vince - 05.09.2012
Some picoseconds, maybe. Neglectable.
Re: Question Relating To Variables -
admantis - 05.09.2012
Variables are not alike strings. The computer reads them differently as you would (probably binary values or hex addresses, can't be sure now), so if you read the variable for "VariableNameHere" or "ThisVariableNameHereIsForTheNumberStorage" or "VarNameNumber", it's all for your comfort and will allow you to understand easily what your variable stores if you have too many of them, for the compiler it's just another address of data. In strings it's different too, but the difference is not noticeable for anyone, but only for the machine. Programmers I know personally (more specific game developers) tend to be descriptive with their variable names so they can identify what they store easily.
1 cell is 4 bytes, so 1 kylobites is 1024 bytes. A string of 128 cells (512 bytes) would be only 0.5 kylobites, so it's not even about speed but memory usage.
Re: Question Relating To Variables -
Kirollos - 05.09.2012
i made debugs with GetTickCount
Код:
[00:58:51] VariableName took 0 ms to be 3!
[00:58:51] VarName took 0 ms to be 3!
pawn Код:
#include <a_samp>
new VariableName = 0;
new VarName = 0;
public OnFilterScriptInit()
{
new tick1 = GetTickCount();
VariableName = 3;
printf("VariableName took %i ms to be %i!", GetTickCount() - tick1, VariableName);
new tick2 = GetTickCount();
VarName = 3;
printf("VarName took %i ms to be %i!", GetTickCount() - tick2, VarName);
}
Re: Question Relating To Variables -
admantis - 05.09.2012
That's not how you do benchmarking, one is not enough, you would have to do that thousands of times (a loop) to get reliable results.
Re: Question Relating To Variables -
Vince - 05.09.2012
In fact, that wasn't even the question. Read please:
Quote:
Originally Posted by Karkand
saving a variable into a file and also reading it
|
In this case we are indeed dealing with strings.
Re: Question Relating To Variables -
leonardo1434 - 05.09.2012
right way, i didn't made a array to use the gettickcount cause it would make it slow for the 2 test.
pawn Код:
public OnFilterScriptInit()
{
static i = 0; // for faster loop.
new VariableName,VarName; // null variables.
new tick1 = GetTickCount(); // start time.
for(; i < 100000000; ++i)
{
VariableName = 3;
}
tick1 = GetTickCount() - tick1;
i = 0; // reseting the static i in non run time counted.
new tick2 = GetTickCount(); // startting new count with another variable
for(; i < 100000000; ++i)
{
VarName = 3;
}
tick2 = GetTickCount() - tick2;
printf("First %d - Second %d", tick1,tick2); // results.
}