Question Relating To Variables
#1

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:

Код:
VarName = 3
Where the length in the variable name is shorter, would I be correct?
Reply
#2

Some picoseconds, maybe. Neglectable.
Reply
#3

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.
Reply
#4

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);
}
Reply
#5

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.
Reply
#6

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.
Reply
#7

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.
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)