What will be faster, MySQL or for loop? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: What will be faster, MySQL or for loop? (
/showthread.php?tid=565924)
What will be faster, MySQL or for loop? -
PaSaSaP - 02.03.2015
For Example if we have MySQL Table with fields: id and nick we can use the next code to get nick:
Code:
new query[64];
mysql_format(MySQLHandler, query, sizeof(query), "SELECT `nick` FROM `TableTest` WHERE `id`=%d", testValue);
mysql_pquery(MySQLHandler, query, "funTest");
[...]
forward funTest();
public funTest()
{
new a[32];
cache_get_row(0, 0, a);
print(a);
return 1;
}
And We have also:
Code:
for(new i; i < MAX; i++)//MAX is integer const
{
if(i == testValue)//testValue is a variable that we can change, it is only example, above also
print(tab[i];//tab is table of nicks
}
My question is: what will be faster, MySQL query on localhost or for loop? For small tabs it for loop will be faster, but what, if we will have 2000 elements?
Re: What will be faster, MySQL or for loop? -
rickisme - 02.03.2015
i think u need change
pawn Code:
SELECT `nick` FROM `TableTest` WHERE `id`=%d
To
pawn Code:
SELECT `nick` FROM `TableTest` WHERE `id`=%d LIMIT 1
and yes, maybe it's faster than loop :-/
Re: What will be faster, MySQL or for loop? -
Vince - 02.03.2015
I seriously doubt that. Pre-compiled code should be way faster.