I don't think any of us wants to start a flame war or anything. My intention is only to clear things up regarding the speed of global vs local vars. And this is NOT about persuading you or anybody else to use global vars in loops, I already said it's not the way to go. The reason I generally bother is the tendency of many, even experienced, scripters to take certain things for granted and to believe and amplify 'rumors' about the performance of various scripting items (I've been guilty of that myself as well). Also note that even though I'm replying to you, I don't do it just for you to read; I hope other people do too and learn something from it.

Take this case, for example. It is generally believed that "GLOBAL VARIABLES = SLOW". This statement is true if we are talking about global vars compared to hash tables (even this is questionable in some cases!). Adding 10000 items in a hash table is much much faster than setting 10000 global vars. But the above statement is not true if the comparison is between global vars and local vars. Creating 10000 local vars is only slightly faster than creating 10000 global ones. Yet, I've heard scripters saying they won't use global variables in on HOTLINK events because they are too slow!

I can't benchmark your /addstats alias, as it contains custom identifiers and other stuff that could corrupt the results of the benchmark, but I tested a similar set of aliases:
Code:
alias testvars1 {
  var %t = $ticks
  %a = 10000
  while %a {
    %b = %a
    %c = %b
    %d = %c
    %e = %d
    %f = %e
    %g = %f
    %h = %g
    %i = %h
    %j = %i
    dec %a
  }
  echo -s testvars1: $calc($ticks - %t)
}
alias testvars2 {
  var %t = $ticks
  var %a = 10000
  while %a {
    var %b = %a
    var %c = %b
    var %d = %c
    var %e = %d
    var %f = %e
    var %g = %f
    var %h = %g
    var %i = %h
    var %j = %i
    dec %a
  }
  echo -s testvars2: $calc($ticks - %t)
}
alias testvars3 {
  var %t = $ticks
  var %a = 10000, %b, %c, %d, %e, %f, %g, %h, %i, %j
  while %a {
    %b = %a
    %c = %b
    %d = %c
    %e = %d
    %f = %e
    %g = %f
    %h = %g
    %i = %h
    %j = %i
    dec %a
  }
  echo -s testvars3: $calc($ticks - %t)
}
You may be surprised (assuming that you care :tongue:) to see that all 3 aliases are very close together (performance-wise) and that /testvars2 is the slowest of the 3, with /testvars3 being the fastest.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com