mIRC Home    About    Download    Register    News    Help

Print Thread
#183758 22/08/07 11:33 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
say if i have something like this

raw -q mode $chan +q $nick $+ $crlf $+ mode $chan -q $nick $+ $crlf $+ mode $chan +v $nick

is it a better code practise to set the $nick and $chan as vars??

var %chan = $chan
var %nick = $nick

raw -q mode %chan +q %nick $+ $crlf $+ mode %chan -q %nick $+ $crlf $+ mode %chan +v %nick

im wondering how mirc is accessing the identifiers like $nick and $chan and if its faster to access by vars (even though the speed isnt human recognisable, im just interested if its better to access by variables instead of calling identifiers repeatedly)

pouncer #183760 22/08/07 11:45 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
You can test things like this yourself by doing a simple loop test using $ticks.

Code:
alias speedtest {
  var %cnt = 1
  var %ticks = $ticks
  while (%cnt <= 5000) {
    noop mode $chan +q $snicks $+ $crlf $+ mode $chan -q $snicks $+ $crlf $+ mode $chan +v $snicks
    inc %cnt
  }
  echo -a Time to complete: $calc(($ticks - %ticks) / 1000)
}


**Call the alias from a channel with a nick selected in your nick list**

Then do the same by replacing all of the identifiers with variables.

Also consider that $+() is often better than a lot of $+'s.

Last edited by Riamus2; 22/08/07 11:47 AM.

Invision Support
#Invision on irc.irchighway.net
Riamus2 #183761 22/08/07 11:49 AM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
thats odd, the vars one came out slightly slower for me

Time to complete: 13.656 for your code
Time to complete: 13.672 for vars

Code:
alias speedtest {
  var %cnt = 1
  window @SpeedTest
  var %ticks = $ticks, %chan = $chan, %snicks = $snicks
  while (%cnt <= 5000) {
    echo @SpeedTest mode %chan +q %snicks $+ $crlf $+ mode %chan -q %snicks $+ $crlf $+ mode %chan +v %snicks
    inc %cnt
  }
  echo -a Time to complete: $calc(($ticks - %ticks) / 1000)
}

Last edited by pouncer; 22/08/07 11:50 AM.
pouncer #183768 22/08/07 01:12 PM
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
alias speedtest1 {
  var %cnt = 10000, %ticks = $ticks
  while (%cnt) {
    noop mode $chan +q $snicks $+ $crlf $+ mode $chan -q $snicks $+ $crlf $+ mode $chan +v $snicks
    dec %cnt
  }
  echo -a (speedtest1): $calc(($ticks - %ticks) / 1000)
}
alias speedtest2 {
  var %cnt = 10000, %ticks = $ticks, %chan = $chan, %snicks = $snicks
  while (%cnt) {
    noop mode %chan +q %snicks $+ $crlf $+ mode %chan -q %snicks $+ $crlf $+ mode %chan +v %snicks
    dec %cnt
  }
  echo -a (speedtest2): $calc(($ticks - %ticks) / 1000)
}
alias speedtest {
  var %cnt = 5
  while (%cnt) {
    speedtest1
    speedtest2
    linesep -a
    dec %cnt
  }
}


/speedtest

I get:

Quote:
(speedtest1): 1.265
(speedtest2): 0.547
-
(speedtest1): 1.203
(speedtest2): 0.563
-
(speedtest1): 1.265
(speedtest2): 0.547
-
(speedtest1): 1.187
(speedtest2): 0.563
-
(speedtest1): 1.203
(speedtest2): 0.547


Seems that %vars are faster. That's when you're doing 10,000 loops though. When using them once the difference is going to be a couple of milliseconds at best.

Edit: in fact, it will be slower to use vars one time, because you're going to have to evaluate the identifier to set the variable, and then use the variable. It'll be quicker to use the identifier directly.

Last edited by hixxy; 22/08/07 01:17 PM.
hixxy #183769 22/08/07 01:19 PM
Joined: Oct 2005
Posts: 827
P
pouncer Offline OP
Hoopy frood
OP Offline
Hoopy frood
P
Joined: Oct 2005
Posts: 827
ahh you changed it to noop, thankss!

pouncer #183836 23/08/07 12:01 AM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Sorry, you read it while I was changing it. Note also that you might want to change $snicks to $me as that would probably affect the speed and $me is probably closer to having the same evaluation time as $nick. Even so, vars seem to be faster. Again, unless you're doing major things (such as 5000+ loops), the difference is so small as to not matter.


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard