alias TestLoops {
var %str = $str(a $chr(32),254)
var %x = $uptime(system)
LoopByStackA %str
echo -- time taken for stack loop: $calc($uptime(system) - %x)
%x = $uptime(system)
LoopByHeap1 %str
echo -- time taken for heap loop #1: $calc($uptime(system) - %x)
%x = $uptime(system)
LoopByHeap2 %str
echo -- time taken for heap loop #2: $calc($uptime(system) - %x)
}
alias LoopByStackA {
if ($0 == 1) {
return
}
LoopByStackB $2-
}
alias LoopByStackB {
if ($0 == 1) {
return
}
LoopByStackA $2-
}
alias LoopByHeap1 {
var %str = $1-
var %x = $gettok(%str,0,32)
while (%x != 1) {
%str = $gettok(%str,2-,32)
dec %x
}
}
alias LoopByHeap2 {
var %str = $1-
while ($gettok(%str,2-,32) != $null) {
%str = $v1
}
}