mIRC Home    About    Download    Register    News    Help

Print Thread
Which one can be perform faster #190391 20/11/07 05:48 AM
Joined: Nov 2007
Posts: 7
M
MrNard Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Nov 2007
Posts: 7
i'm also confius about this kind structure of code..

which on can be perform faster
e.g :
var %x

i) if (x==1) set %a = x
if (x==2) set %a = x
if (x==3) set %a = x

ii) if (x==1 || x==2 || x==3) set %a = x

iii) or $iff is proper tu use



Re: Which one can be perform faster [Re: MrNard] #190392 20/11/07 06:00 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
The second one will be faster (technically). This is because mIRC will stop the comparison as soon as the first match is found, and skip to the action. An equivalent would be something like this:

if (x == 1) ;blah1
elseif (x == 2) ;blah2
elseif (x == 3) ;blah3

In this case, as soon as the first match is found and the associated action is taken, mIRC skips to the line directly after the last elseif (or else) in that if-statement.

Someone else can probably describe this better using colors and/or diagrams.

-genius_at_work

Re: Which one can be perform faster [Re: MrNard] #190393 20/11/07 06:24 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Ive also found that if it is all in one line it can perform faster.

I did a test wondering if using pipes were faster or not. It turned a line using pipes was faster than spreading it out on each line. (I do not advocate overusing pipes, my test invloved 4 or 5 in one line.)

I assumed this was because it was all on one line. If a script is read line by line, it would grab all information in the ONE line and process each faster than if it would go to each step on a seperate line.

Again, the "WHY" is speculation, but the tests showed pipes (using one line) can be a bit faster than using multiple lines.

This is why I think your 2nd option is faster, as well as what Genius said. If the first comparison is true it will just skip to the command.

Also, $iif is much slower than if (comparison) { command }.

$iif is nice to use when a traditional if statement cannot be used. Other than that, try and always use if.

Re: Which one can be perform faster [Re: DJ_Sol] #190420 20/11/07 07:14 PM
Joined: Nov 2007
Posts: 7
M
MrNard Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
M
Joined: Nov 2007
Posts: 7
Thanks guys.. i'm also think the 2nd one much better than all.. thanks again for ur opinion..

Re: Which one can be perform faster [Re: MrNard] #190424 20/11/07 07:54 PM
Joined: Oct 2007
Posts: 214
B
Buggs2008 Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Oct 2007
Posts: 214
what does the pipe look like?

is: msg # hello $+ crlf $+ msg # testing

faster than : msg # hello | msg # testing


???

Re: Which one can be perform faster [Re: Buggs2008] #190425 20/11/07 09:03 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Uhm, this all is about milliseconds (or a fractional amount of a millisecond) and rarely of practical importance, but for huge while-loops and the like.
Due to the normal "lag" of an irc network structure it does not matter in terms of sending text (or commands). smile

Re: Which one can be perform faster [Re: Horstl] #190432 20/11/07 10:32 PM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline
Babel fish
Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
Are there any guidelines to make scripts work faster else then described above?

Re: Which one can be perform faster [Re: ots654685] #190434 20/11/07 11:34 PM
Joined: Nov 2006
Posts: 1,559
H
Horstl Offline
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
Imho, more important than the question of brackets, pipes and the like (example of benchmarking) is "logic", for example a a most logical order of conditions or e.g. the use of "elseif" etc whenever possible.
Hash tables can speed up things; regular expressions can replace a bundle of if-comparisons at once; using the "command" parameter in $findfile can improve it's performance alot...
Avoid unnecessary double evaluations like "if (($active ischan) && ($me isop $active))" (you can only be op on a channel) or "if ((!$1) || (!$2))" (if the first is missing, the second is missing for sure laugh ), be as definite as possible, for example in event definitions...
There is always more than one way to make something work, and the best solution for one problem had not to be the best for another one. And, finally, I'd always prefer a clean&neat code to code that processes 0.03ms faster smile

Re: Which one can be perform faster [Re: ots654685] #190439 21/11/07 12:26 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Well, Horstl is right, its all milli-seconds difference per line, but the way I look at it, it all adds up. One milli-second faster here and there, always writing code to make mIRC work the least as possible all adds up.

Guidelines?

Always try to use proper mIRC coding.

if (comparison) { command }

yes I don't have to use { } around command but that means mIRC takes the time to put them there.

Use static names and paths when possible.
Something like $dname will return the dialog name in the event, but writing the actual dialog name instead is faster, making mIRC work less. Do this whenever possible.

Hash Tables are great and fast. I also like to keep my variable list as clean as possible.

$+(data1,data2) is faster than data1 $+ data2

If you do one or two of these things once in your code you may not notice much of a difference. But if you adopt this in all your code I guarantee you will see a difference in speed and response.

Re: Which one can be perform faster [Re: DJ_Sol] #190454 21/11/07 03:33 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
Originally Posted By: DJ_Sol

yes I don't have to use { } around command but that means mIRC takes the time to put them there.


mIRC doesn't 'put them there', quite the contrary, the {} need to be parsed so that's a tiny bit of extra work. you seem to have the wrong idea of how mIRC processes code, it wouldn't add/modify anything except in certain situations, eg. replacing %var = with set %var and other things of this nature (this is just to make things convenient i spose)


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Which one can be perform faster [Re: jaytea] #190458 21/11/07 06:04 AM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
well I've tested both methods, not using brackets was slightly slower than using them. Yes you are right, I only assumed the reason. Don't know why then, but using brackets is faster than not.

Re: Which one can be perform faster [Re: DJ_Sol] #190461 21/11/07 06:36 AM
Joined: Dec 2002
Posts: 503
B
Bekar Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Dec 2002
Posts: 503
With brackets in place, mIRC doesn't have to do as much work to figure out where the if's command structure ends. It knows it goes to the next } in the parse tree.

Without it, it's gotta nibble along until it comes to a | or an end-of-line..

Re: Which one can be perform faster [Re: Bekar] #190469 21/11/07 11:43 AM
Joined: Feb 2006
Posts: 97
O
ots654685 Offline
Babel fish
Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
And what about using hash tables or ini files?
Does using hash tables make it faster or strip down code lines instead of using ini commands?

-update-
imo it's better to use hash tables so you would have less code and less read/write commands what could speed up things.

Last edited by ots654685; 21/11/07 12:06 PM.
Re: Which one can be perform faster [Re: ots654685] #190493 21/11/07 04:39 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
Not only do hash tables use less code to work with, they are the fastest way of retrieving stored data in mIRC.

(Some folks are using SQL Tables which is faster)

Just dont get carried away with hash tables. From what I was told mIRC doesn't manage your RAM the best.

I have two main tables. One for general, one for protections. If it is not data that I will access a lot I will store it in a variable or an ini file.

It's better to share a table than to open up three tables that hold one piece of information each.

Again this is the same philosphy. Doing it once isn't a big deal but it adds up. To really make a difference by writing clean code that operates the fastest and most efficient, use these tips in everything you write.

Re: Which one can be perform faster [Re: jaytea] #190497 21/11/07 05:44 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
replacing %var = with set %var and other things of this nature


I have a question about this. When making local variables I usually set them at the beginning of the script with their correct value and "bookmark" local variables that don't have a value but will be given one in the script.

var %ex = blah, %new

So then in my script I say:

%new = newvalue

Is it better for me to say:

var %new = newvalue


Is it better for me to use the /var command everytime in a script? I had always designated the local variable at the beginning.

Re: Which one can be perform faster [Re: DJ_Sol] #190501 21/11/07 06:07 PM
Joined: Jul 2006
Posts: 3,668
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,668
Using /var %var = value and then %var = value is faster than using /Var %var = value and then var %var = value

And in this case, the speed is quite important.

Edit : since mIRC 6.3, the egal sign isn't required,

Last edited by Wims; 21/11/07 06:12 PM.

Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Which one can be perform faster [Re: DJ_Sol] #190528 22/11/07 02:25 AM
Joined: Feb 2006
Posts: 546
J
jaytea Offline
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
better? up to you man ;p don't let these highly negligible differences in processing time influence your decision. use whatever makes most sense to you

!set %var value is technically the quickest way to assign a value to a previously declared local variable, but i certainly wouldn't get into the habit of using it just for that. the ! looks a bit weird, and glancing over the code later (and having forgotten that the variable was already declared) i might wonder why i'm setting that variable globally, when im not

i suppose personally i'd use %var = value since i find it cleanest :p


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Re: Which one can be perform faster [Re: jaytea] #190538 22/11/07 08:36 AM
Joined: Jul 2006
Posts: 3,668
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,668
Originally Posted By: jaytea
i suppose personally i'd use %var = value since i find it cleanest :p
Event if it can be cleaner, this syntax doesn't allow you to use the -s switch, that show you the value.It's why i personnaly use /Var %var [=] value in any case.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Which one can be perform faster [Re: jaytea] #190540 22/11/07 09:04 AM
Joined: Apr 2004
Posts: 759
M
Mpdreamz Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Apr 2004
Posts: 759
Originally Posted By: jaytea
!set %var value is technically the quickest way to assign a value to a previously declared local variable,
..

Would it lose alot of speed if you did !set -l %var value ?

I personally go for %var = value as well, because in most languages your not even allowed to redeclare a variable in the same scope.


$maybe