mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
#171443 24/02/07 12:46 PM
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
In a recent post, Kardafol stated,
"Also, don't leave out brackets, as it slows the script down as mIRC will have to place them itself ..."

I do not doubt you whatsoever. I would like to see what other people say about this. I would like to verify this information as this is rather integral I feel. A script full of missing brackets would be extremely slower than one that wasnt missing any. (Not talking bracket mismatch, you know what I mean.)

Some points from the help file:
If-then-else section:
Using brackets speeds up processing. If an alias uses too few brackets then the statement might be ambiguous and the alias will take longer to parse, might be parsed incorrectly, or might not be parsed at all.

From Aliases section:
the command prefix is really only needed when entering a command on the command line. In scripts, all lines are assumed to start with a command, so you don't need to use the / command prefix.




Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
The alias thing from the text file isn't anything to do with brackets. laugh

As for the speed and bracket connection, it could be true. I've never done any tests. I use {}'s all of the time as well as appropriate ()'s around IFs and such. I prefer proper syntax, so it hasn't ever been an issue for me.


Invision Support
#Invision on irc.irchighway.net
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Tests and discussions have gone on about this before. As I recall the general rule is this:

When multiple commands are being called:
statement condition {
commands
}

is faster than
statement (condition) {
commands
}


When a single command is being called:
statement (condition) command
is faster than
statement condition { command }
is faster than
statement (condition) { command }
is faster than
statement condition command

Whether that's still true, whether that's always true, and whether the speed benefits actually matter or not, I don't know.


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Jan 2007
Posts: 1,156
D
DJ_Sol Offline OP
Hoopy frood
OP Offline
Hoopy frood
D
Joined: Jan 2007
Posts: 1,156
The reason I asked was for commands like starbucks_mafia pointed out.

When a single command is being called:
statement (condition) command
is faster than
statement (condition) { command }

According to this, then the way I code is the best known way. I thought Karadafol was suggesting I should change my scripts to statement (condition) { command }.

I use brackets if there is a more than one command.
if (comparison) { command | command }
otherwise I like to say
if (comparison) command

Anyone else have any thoughts on this?



Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
This could be tested, but imo, it's always best to use proper syntax, which means appropriate ()'s and {}'s. Also, you would need a LOT of scripts loaded (probably at least 10MB worth) to make it a noticeable difference in speed. If all you save is 5ms, it's not exactly helpful to anyone. I'd rather see scripts use proper syntax. Just my opinion.


Invision Support
#Invision on irc.irchighway.net
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
if (...) ... is still the fastest way to execute single commands if certain conditions are met.

Joined: Jan 2003
Posts: 1,063
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Jan 2003
Posts: 1,063
which would be no more then logical really.

if mIRC encounters {} it will treat the code in between as possible multiple commands and probably has to do stuff to prepare itself for such commands. if only one command is given it's just waisted overhead...

I also try to use (){} because it simply makes the code easier to read alot of the time


If it ain't broken, don't fix it!
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Yeah, as I said, it's a really minor change in speed, so using the expected syntax would be better, imo.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2007
Posts: 75
T
Babel fish
Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Recently I have been wondering this myself. I happen to be one of the scripters on a DCC chat based MUD Game bot, where speed is improtant.

The discussion came to asking if it would be faster to use .msg instead of msg.

My question is, if it really would make a noticable speed boost?


GigIRC Network Admin
irc.gigirc.com
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
If you're going to notice a speed boost of that level, then you're being very particular to your speed timings. The main difference between .msg and msg (or /msg) is the fact that the message doesn't have to be displayed on your own client.

The timing difference, if I recall correctly, is aproximately 1 millisecond for each 100 characters. This timing was done a while back when I was wondering the same thing. Computer speeds have increased in the mean time, so the actual difference with a current system (I suspect) would be even smaller.

When I tested those timings, I was running a PIII 600 with 128M RAM. You can do a quick estimate by comparing your system with that configuration to see what the time difference on your system would probably be.

Joined: Feb 2007
Posts: 75
T
Babel fish
Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Then I guess there would be a noticable speed boost in a game like this, being very verbose and having a large amount of user playing it at one time. Thanx for the info, RusselB smile


GigIRC Network Admin
irc.gigirc.com
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
no prob...just don't ask me for the details on how I got those numbers...I've lost the actual code, but found the text file that I generated for a report, so I can confirm the numbers I reported are accurate.

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Trixar_za
Then I guess there would be a noticable speed boost in a game like this, being very verbose and having a large amount of user playing it at one time. Thanx for the info, RusselB smile


Not necessarily. You can only fit about 400-500 characters on a line on most networks before they cut your text off. That means only about 4-5ms difference per line. Even if your bot said 5 full lines in a second (more than that and it would be kicked off for flooding and no one could read that fast anyhow), you're still only talking about a 20-25ms difference. Believe me... you're not going to notice that difference.

Also, *ONLY* the bot's text would have an effect by changing the /msg lines. Everyone else's text wouldn't be affected by changing those.


Invision Support
#Invision on irc.irchighway.net
Joined: Nov 2003
Posts: 67
C
Babel fish
Offline
Babel fish
C
Joined: Nov 2003
Posts: 67
Originally Posted By: Yochai
* Don't use excessive Braces { } where you don't need them, and you only need them when there's more then one line in the command.

The { Brace means "Begin" and the } Brace means "End" so if there's only one line to the event or command, you don't need to give the script a beginning and end command.

For example:

ON *:text:*:*: { if ($nick = Blah) { do something here } }

Which the scrip reads like this: ON *:text:*:*: Begin-event if ($nick = Blah) Begin-if do something here End-if End-event

So as you see, you don't need to tell it where to begin and end if there's only one line.

So this would better:

ON *:text:*:*: if ($nick = Blah) do something here

Now besides the fact that it's useless to put excessive Braces, they all use more CPU.

That's because the { Begin Brace is actually a command that calls a procedure to check for the } End Brace (and run all the commands between of course).

It doesn't take a lot of CPU of course, but it's about the same amount as calling an alias (see "Saving CPU/memory usage").


Advance Scripting Tips by Yochai uploaded in mircscripts.org http://www.mircscripts.org/comments.php?cid=2778


irc.universochat.net
#escripting
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
And at the same time, I dislike multiple things on a single line. That includes an event line with a command after it. Yes, it probably saves a couple miliseconds (not that you'd ever notice it). Yes, it saves you a couple of lines. However, it can make reading through scripts a royal pain and I really hate having people ask me for help with a script and then I have to try and sort through one that has multiple things on each line and excessive pipe use and such.


Invision Support
#Invision on irc.irchighway.net
Joined: Jan 2007
Posts: 259
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Jan 2007
Posts: 259
Originally Posted By: Canario
Originally Posted By: Yochai
* Don't use excessive Braces { } where you don't need them, and you only need them when there's more then one line in the command.

The { Brace means "Begin" and the } Brace means "End" so if there's only one line to the event or command, you don't need to give the script a beginning and end command.

For example:

ON *:text:*:*: { if ($nick = Blah) { do something here } }

Which the scrip reads like this: ON *:text:*:*: Begin-event if ($nick = Blah) Begin-if do something here End-if End-event

So as you see, you don't need to tell it where to begin and end if there's only one line.

So this would better:

ON *:text:*:*: if ($nick = Blah) do something here

Now besides the fact that it's useless to put excessive Braces, they all use more CPU.

That's because the { Begin Brace is actually a command that calls a procedure to check for the } End Brace (and run all the commands between of course).

It doesn't take a lot of CPU of course, but it's about the same amount as calling an alias (see "Saving CPU/memory usage").


Advance Scripting Tips by Yochai uploaded in mircscripts.org http://www.mircscripts.org/comments.php?cid=2778

Wrong. The { bracket ISN'T a command to "search for another } bracket and..."
The { bracket is a command to, execute all uncomented commands and statements untill it finds a } bracket. It looses time by reading the next line.
Proof?
Code:
alias test {

echo -a 123


If what you're saying is right, then the above will NOT work. It does.


Those who can, cannot. Those who cannot, can.
Joined: Feb 2007
Posts: 75
T
Babel fish
Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
It a dcc chat based game btw :P .

It's a very menu and text driven game, so it easly generates 5 or more lines in less than a second(longest menu is around 15 lines, if I remember correctly).

Now take this in account with a average of 5-7 players connected and playing at one time, which gives a minor but noticable speed difference.

Also changed the notice and amsg to there repective none showing counter parts smile

Have to say this conversation is getting more interesting by the day smile


GigIRC Network Admin
irc.gigirc.com
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
I change my coding style all the time, I should really try and stick to one thing.

One minute I'll be using if ($x != $null) { ... } and the next I'll be using if (* iswm $x) ...

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Most networks will not allow more than about 5 lines in a second without it flooding you off. /play is designed for such things. Better yet, if it's that menu-driven, creating a mini-client for players to download and use is very helpful as well.

Even then... let's say you do a 100 lines of text in a second at even 5ms difference for using {}'s (and that's more than it really is), you'd still only see a half second difference. Yes, it may be a little noticeable, but most people's LAG is more than that, so it's not really an issue, imo.

Either way, it's your script and you can do anything you want with it. I just normally don't bother helping with questions about scripts that have multiple things on one line (overusing pipes) or ones that don't use {}'s because it makes it more difficult to figure out where everything is in the script. When it's your own script and you already know the flow of it, it's not an issue. For someone trying to help you who has never seen the script, it makes it more of a pain, imo.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2007
Posts: 75
T
Babel fish
Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Yeah, it is is like that hey. I didn't originally write the game, more of became part of it after the fact.

After cleaning the mess the previous scripters made(about 2 days worth of mess smirk ) and some restructering, I was stuck being the only one that understood the bot smirk

Now I'm more busy trying to speed it up and make it more cheat free as possible, so expect a lot of post from me asking how to do some things :P


GigIRC Network Admin
irc.gigirc.com
Page 1 of 2 1 2

Link Copied to Clipboard