SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 02/03/2015, 07:27 AM   #1
PaSaSaP
Little Clucker
 
Join Date: Jan 2015
Posts: 23
Reputation: 0
Default What will be faster, MySQL or for loop?

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?
PaSaSaP is offline   Reply With Quote
Old 02/03/2015, 08:27 AM   #2
rickisme
Huge Clucker
 
rickisme's Avatar
 
Join Date: Mar 2013
Location: Vietnam
Posts: 225
Reputation: 27
Default Re: What will be faster, MySQL or for loop?

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 :-/
__________________

Sorry for my bad english.
  1. [FS] SoundCloud Music Player
  2. [VIDEO] Horse Betting System
rickisme is offline   Reply With Quote
Old 02/03/2015, 09:11 AM   #3
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,067
Reputation: 2660
Default Re: What will be faster, MySQL or for loop?

I seriously doubt that. Pre-compiled code should be way faster.
__________________
Vince is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Mysql] Faster loading Dj_maryo1993 Scripting Help 3 30/03/2013 05:50 AM
MySQL query: What is faster? FireCat Scripting Help 9 25/07/2012 09:24 AM
for( ) loop vs while( ) loop | While( ) loop is 143x faster? zgintasz Scripting Help 17 03/07/2012 12:57 PM
What is the faster mysql plugins? Fab10 Help Archive 6 16/05/2011 04:28 PM
get mysql variable faster Ribber Help Archive 7 11/10/2010 06:47 PM


All times are GMT. The time now is 05:02 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.