mIRC Homepage
Posted By: MrNard Which one can be perform faster - 20/11/07 05:48 AM
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


Posted By: genius_at_work Re: Which one can be perform faster - 20/11/07 06:00 AM
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
Posted By: DJ_Sol Re: Which one can be perform faster - 20/11/07 06:24 AM
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.
Posted By: MrNard Re: Which one can be perform faster - 20/11/07 07:14 PM
Thanks guys.. i'm also think the 2nd one much better than all.. thanks again for ur opinion..
Posted By: Buggs2008 Re: Which one can be perform faster - 20/11/07 07:54 PM
what does the pipe look like?

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

faster than : msg # hello | msg # testing


???
Posted By: Horstl Re: Which one can be perform faster - 20/11/07 09:03 PM
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
Posted By: ots654685 Re: Which one can be perform faster - 20/11/07 10:32 PM
Are there any guidelines to make scripts work faster else then described above?
Posted By: Horstl Re: Which one can be perform faster - 20/11/07 11:34 PM
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
Posted By: DJ_Sol Re: Which one can be perform faster - 21/11/07 12:26 AM
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.
Posted By: jaytea Re: Which one can be perform faster - 21/11/07 03:33 AM
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)
Posted By: DJ_Sol Re: Which one can be perform faster - 21/11/07 06:04 AM
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.
Posted By: Bekar Re: Which one can be perform faster - 21/11/07 06:36 AM
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..
Posted By: ots654685 Re: Which one can be perform faster - 21/11/07 11:43 AM
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.
Posted By: DJ_Sol Re: Which one can be perform faster - 21/11/07 04:39 PM
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.
Posted By: DJ_Sol Re: Which one can be perform faster - 21/11/07 05:44 PM
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.
Posted By: Wims Re: Which one can be perform faster - 21/11/07 06:07 PM
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,
Posted By: jaytea Re: Which one can be perform faster - 22/11/07 02:25 AM
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
Posted By: Wims Re: Which one can be perform faster - 22/11/07 08:36 AM
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.
Posted By: Mpdreamz Re: Which one can be perform faster - 22/11/07 09:04 AM
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.
© mIRC Discussion Forums