PDA

View Full Version : What will be faster, MySQL or for loop?


PaSaSaP
02/03/2015, 07:27 AM
For Example if we have MySQL Table with fields: id and nick we can use the next code to get nick:
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:
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?

rickisme
02/03/2015, 08:27 AM
i think u need change

SELECT `nick` FROM `TableTest` WHERE `id`=%d

To

SELECT `nick` FROM `TableTest` WHERE `id`=%d LIMIT 1


and yes, maybe it's faster than loop :-/

Vince
02/03/2015, 09:11 AM
I seriously doubt that. Pre-compiled code should be way faster.