mIRC Homepage
Posted By: DJ_Sol Using/Not Using Brackets - 24/02/07 12:46 PM
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.



Posted By: Riamus2 Re: Using/Not Using Brackets - 24/02/07 01:32 PM
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.
Posted By: starbucks_mafia Re: Using/Not Using Brackets - 24/02/07 02:59 PM
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.
Posted By: DJ_Sol Re: Using/Not Using Brackets - 24/02/07 08:39 PM
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?


Posted By: Riamus2 Re: Using/Not Using Brackets - 24/02/07 09:34 PM
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.
Posted By: hixxy Re: Using/Not Using Brackets - 25/02/07 12:22 AM
if (...) ... is still the fastest way to execute single commands if certain conditions are met.
Posted By: Doqnach Re: Using/Not Using Brackets - 26/02/07 01:05 PM
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
Posted By: Riamus2 Re: Using/Not Using Brackets - 26/02/07 02:36 PM
Yeah, as I said, it's a really minor change in speed, so using the expected syntax would be better, imo.
Posted By: Trixar_za Re: Using/Not Using Brackets - 27/02/07 08:21 PM
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?
Posted By: RusselB Re: Using/Not Using Brackets - 28/02/07 12:09 AM
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.
Posted By: Trixar_za Re: Using/Not Using Brackets - 28/02/07 01:23 AM
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
Posted By: RusselB Re: Using/Not Using Brackets - 28/02/07 03:45 AM
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.
Posted By: Riamus2 Re: Using/Not Using Brackets - 28/02/07 02:33 PM
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.
Posted By: Canario Re: Using/Not Using Brackets - 28/02/07 08:08 PM
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
Posted By: Riamus2 Re: Using/Not Using Brackets - 28/02/07 10:19 PM
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.
Posted By: Kardafol Re: Using/Not Using Brackets - 28/02/07 10:37 PM
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.
Posted By: Trixar_za Re: Using/Not Using Brackets - 01/03/07 11:40 PM
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
Posted By: hixxy Re: Using/Not Using Brackets - 02/03/07 10:31 AM
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) ...
Posted By: Riamus2 Re: Using/Not Using Brackets - 02/03/07 02:22 PM
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.
Posted By: Trixar_za Re: Using/Not Using Brackets - 02/03/07 07:48 PM
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
Posted By: DJ_Sol Re: Using/Not Using Brackets - 02/03/07 09:48 PM
Well the reason I started this thread was not for playing a game. I don't see how brackets would improve a single messages speed enough to notice a difference. The reason why I started this thread was because code adds up quick!

One single line or response doesn't make much difference, but when one command turns into a few different processes while other processes are running, it all adds up!

Thank you for clarifying.
It seemed to me that the help file that was shown as an example was someone's opinions about how mIRC works. It seemed to have some valuable ideas for the intermediate scripter, but wasn't completely accurate. Just one guys opinion. Nothing wrong with that, it all helps, but it is hardly a "bible" to base anything on.

My question was answered well. I appreciate your help! smile

© mIRC Discussion Forums