20.07.2010, 02:52
Introduction
Hey, i'm going to start a quick experiment to see what's faster, using normal variables, or PVars. Here's a example of each.
Player variables are new to most scripters. Some prefer it for reasons. This tutorial is split up into several useful information. After talking with my friend krisk about z-Andreas we somehow drifted to a discussion of variables and speed, etc. Quoted from krisk:
I decided actually to check if this is true, by the end of this experiment you will find out of course. We're going to use this code for testing.
Speed-O-Krisk
Lets test krisk's opinion, here's what he would do for proof or whatever.
Ok, fine, lets now test the outcome.
Speed-O-Carlton
Ok, it's my turn, this is my code I would use.
Ok, now it's time to test the speed.
Before the results.
Before the results i'd like to type a little note explaining that SetPVarInt and GetPVarInt calls the function and does what it needs but on the other hand variables does the opposite, it just does what it needs. But then again variables create more cells which means longer compiling.
RAM speed can also do something about the results.
Results #1
Ok, they both came out to be zero. "Oh WTF?". No one ever said variables are faster than a milliseconds even bring to "nanoseconds"!
Results #2
I tried something different.
Results came in.
Oh look we're getting somewhere.
Conclusion
Ok, looks like krisk beat me, and was right, i'll buy him a stack of beer or something. The outcome of this experiment and a summary:
Thank you for reading this, I hope people who didn't know learned something today, because I did.
Hey, i'm going to start a quick experiment to see what's faster, using normal variables, or PVars. Here's a example of each.
pawn Код:
// Normal.
new
GSystem[MAX_PLAYERS];
pawn Код:
// PVars
SetPVarInt(playerid, "GSystem", 0);
Quote:
Originally Posted by IRC
<krisk> PVars are convinient but still variables are twice as fast
|
pawn Код:
new
string[70],
pname[24];
GetPlayerName(playerid, pname, 24);
format(string, 70, "SELECT * FROM Accounts WHERE Username = '%s'", name);
mysql_query(string); mysql_store_result();
if(mysql_num_rows() > 0) {
// Variable information we're experimenting.
}
else {
}
mysql_free_result();
Lets test krisk's opinion, here's what he would do for proof or whatever.
pawn Код:
new
string[70],
pname[24],
bool:HasAccount[MAX_PLAYERS];
GetPlayerName(playerid, pname, 24);
format(string, 70, "SELECT * FROM Accounts WHERE Username = '%s'", name);
mysql_query(string); mysql_store_result();
if(mysql_num_rows() > 0) HasAccount[playerid] = true;
else HasAccount[playerid] = false;
mysql_free_result();
pawn Код:
new
string[70],
pname[24],
bool:HasAccount[MAX_PLAYERS],
StartTest, EndTest;
GetPlayerName(playerid, pname, 24);
format(string, 70, "SELECT * FROM Accounts WHERE Username = '%s'", name);
mysql_query(string); mysql_store_result();
StartTest = GetTickCount();
if(mysql_num_rows() > 0) HasAccount[playerid] = true;
else HasAccount[playerid] = false;
EndTest = GetTickCount();
printf("krisk's varable method: %i", EndTest - StartTest);
mysql_free_result();
Ok, it's my turn, this is my code I would use.
pawn Код:
new
string[70],
pname[24];
GetPlayerName(playerid, pname, 24);
format(string, 70, "SELECT * FROM Accounts WHERE Username = '%s'", name);
mysql_query(string); mysql_store_result();
if(mysql_num_rows() > 0) SetPVarInt(playerid, "HasAccount", true);
else SetPVarInt(playerid, "HasAccount", false);
mysql_free_result();
pawn Код:
new
string[70],
pname[24],
StartTest, EndTest;
GetPlayerName(playerid, pname, 24);
format(string, 70, "SELECT * FROM Accounts WHERE Username = '%s'", name);
mysql_query(string); mysql_store_result();
StartTest = GetTickCount();
if(mysql_num_rows() > 0) SetPVarInt(playerid, "HasAccount", true);
else SetPVarInt(playerid, "HasAccount", false);
EndTest = GetTickCount();
printf("Carlton's varable method: %i", EndTest - StartTest);
mysql_free_result();
Before the results.
Before the results i'd like to type a little note explaining that SetPVarInt and GetPVarInt calls the function and does what it needs but on the other hand variables does the opposite, it just does what it needs. But then again variables create more cells which means longer compiling.
RAM speed can also do something about the results.
Results #1
Ok, they both came out to be zero. "Oh WTF?". No one ever said variables are faster than a milliseconds even bring to "nanoseconds"!
Quote:
krisk's varable method: 0 Carlton's varable method: 0 |
I tried something different.
pawn Код:
for(new gg = 0; gg < 100000; gg ++ ) SetPVarInt(playerid, "HasAccount", true);
for(new gg = 0; gg < 100000; gg ++ ) HasAccount[playerid] = true;
Quote:
Originally Posted by Server
[22:42:25] Krisk's test took: 14
[22:42:25] Carlton's test took: 40 |
Conclusion
Ok, looks like krisk beat me, and was right, i'll buy him a stack of beer or something. The outcome of this experiment and a summary:
- 1: Create the code.
- 2: Get how fast it's without setting it about 100k times
- 3: Conclude
Thank you for reading this, I hope people who didn't know learned something today, because I did.