mIRC Home    About    Download    Register    News    Help

Topic Options
#185475 - 10/09/07 12:47 AM Whats Faster? $remove or $gettok
DJ_Sol Offline
Hoopy frood

Registered: 04/01/07
Posts: 1156
Loc: Seattle
var %ex = $remove(sho.#chan,sho.)

-or-

var %ex = $gettok(sho.#chan,-1,46)


Which is faster?


Edited by DJ_Sol (10/09/07 12:47 AM)

Top
#185476 - 10/09/07 01:06 AM Re: Whats Faster? $remove or $gettok [Re: DJ_Sol]
jaytea Offline
Fjord artisan

Registered: 23/02/06
Posts: 546
1. try benchmarking

2. consider speed in the right circumstances

i say this a lot, but everyone always brings up speed when it's least relevant :S why would you compare the speeds of these 2 distinctly different operations? it makes much more sense to discuss suitability, and the question here should be what is most suitable.

the input (sho.#chan in this case), does it always start with 'sho.'? are you always trimming off the first 4 characters? in which case $mid(sho.#chan,5) is most suitable and quite possibly the 'quickest'. i wouldn't use $remove() at all, what if the channel contains 'sho.'?

i perhaps wouldn't even use $gettok() even if the 'sho' was variable and you always wanted the channel after the first . since $gettok() removes excess delimiters and would turn #ch...an into #ch.an. this might not be an issue for you, but if i were releasing a script and interested in the most "proper" method, these are things i'd think of
_________________________
"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde

Top
#185477 - 10/09/07 01:40 AM Re: Whats Faster? $remove or $gettok [Re: jaytea]
DJ_Sol Offline
Hoopy frood

Registered: 04/01/07
Posts: 1156
Loc: Seattle
Thanks for replying.

It always begins with sho. Maybe I'll just use $mid then.

Top
#185479 - 10/09/07 03:31 AM Re: Whats Faster? $remove or $gettok [Re: DJ_Sol]
Riamus2 Offline
Planetary brain

Registered: 13/10/04
Posts: 8327
Loc: MA, USA
As suggested, just benchmark anytime you want to figure out which is faster. To benchmark, you need to do a lot of repetitions and use $ticks to calculate it.

Example:
Code:
alias SpeedTest {
  ;Test 1
  var %ticks = $ticks, %cnt = 1
  while (%cnt <= 20000) {
    var %ex = $remove(sho.#chan,sho.)
    inc %cnt
  }
  echo -a Using Remove: $calc($ticks - %ticks)

  ;Test 2
  var %ticks = $ticks, %cnt = 1
  while (%cnt <= 20000) {
    var %ex = $gettok(sho.#chan,-1,46)
    inc %cnt
  }
  echo -a Using Gettok: $calc($ticks - %ticks)

  ;Test 3
  var %ticks = $ticks, %cnt = 1
  while (%cnt <= 20000) {
    var %ex = $left(sho.#chan,-4)
    inc %cnt
  }
  echo -a Using Left: $calc($ticks - %ticks)

  ;Test 4
  var %ticks = $ticks, %cnt = 1
  while (%cnt <= 20000) {
    var %ex = $mid(sho.#chan,5-)
    inc %cnt
  }
  echo -a Using Mid: $calc($ticks - %ticks)
}


Note that you can divide your $calc by 1000 if you want it in seconds instead of milliseconds, but it doesn't really matter.

My own tests show (after 4 tests):
$Remove: 1062, 1031, 1031, 1015
$Gettok: 1078, 1032, 1031, 1031
$Left: 1047, 1000, 1000, 985
$Mid: 1078, 1015, 1000, 1000

Just to make it easier to see, here's an average of the 4 tests:
$Remove: 1034.75
$Gettok: 1043
$Left: 1008
$Mid: 1023.25

So, just from those 4 tests at 20,000 repetitions, you can see that $Left is the fastest on average out of the 4 methods I tested. $Mid tends to be second fastest, though it was the slowest in the first test. $Remove is third and $Gettok is slightly slower or equal to $Remove.

You can perform a similar test on ANY kind of operation you want to test speed on. It isn't hard to adjust this test to work with any other command. Just replace the var lines with whatever you are testing and increase or decrease the number of tests depending on the number of methods you are testing.
_________________________
Invision Support
#Invision on irc.irchighway.net

Top
#185495 - 10/09/07 06:09 AM Re: Whats Faster? $remove or $gettok [Re: Riamus2]
DJ_Sol Offline
Hoopy frood

Registered: 04/01/07
Posts: 1156
Loc: Seattle
Sweet thanks! $left it is!

Top
#185499 - 10/09/07 08:08 AM Re: Whats Faster? $remove or $gettok [Re: DJ_Sol]
Horstl Offline
Hoopy frood

Registered: 03/11/06
Posts: 1559
Loc: Germany
//echo -a thats $calc((1043 - 1008) / 20000) ms faster than gettok!
But seriously: Riamus2 depicted well how you can start your own tests in the future, and jaytea pointed out that speed is not everything to take into account.

Top
#185504 - 10/09/07 09:36 AM Re: Whats Faster? $remove or $gettok [Re: DJ_Sol]
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
Actually that would be $right (try $left(sho.#chan,-4) to see what it returns).
_________________________
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Top
#185505 - 10/09/07 11:38 AM Re: Whats Faster? $remove or $gettok [Re: qwerty]
SplitFire Offline
Ameglian cow

Registered: 03/09/07
Posts: 32
Loc: Neverlands
not much of a difference
the milliseconds lag between each method and the others can't be noticed by you as a user and won't criticaly affect any operation you might be performing using any of the methods you mentioned
_________________________
on me:*:JOIN:#: { .raw part # $crlf join # }

Top