What will be faster, MySQL or for loop?
#1

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?
Reply
#2

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 :-/
Reply
#3

I seriously doubt that. Pre-compiled code should be way faster.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)