mIRC Home    About    Download    Register    News    Help

Print Thread
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



Joined: Oct 2005
Posts: 1,741
G
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

Joined: Jan 2007
Posts: 1,156
D
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.

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..

Joined: Oct 2007
Posts: 214
B
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


???

Joined: Nov 2006
Posts: 1,559
H
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

Joined: Feb 2006
Posts: 97
O
Babel fish
Offline
Babel fish
O
Joined: Feb 2006
Posts: 97
Are there any guidelines to make scripts work faster else then described above?

Joined: Nov 2006
Posts: 1,559
H
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

Joined: Jan 2007
Posts: 1,156
D
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.

Joined: Feb 2006
Posts: 546
J
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
Joined: Jan 2007
Posts: 1,156
D
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.

Joined: Dec 2002
Posts: 503
B
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..

Joined: Feb 2006
Posts: 97
O
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.
Joined: Jan 2007
Posts: 1,156
D
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.

Joined: Jan 2007
Posts: 1,156
D
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.

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2006
Posts: 546
J
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
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
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.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Apr 2004
Posts: 759
M
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

Link Copied to Clipboard