slang-users mailing list

[2005 Date Index] [2005 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

Re: [slang-users] advantage of $1 over a variable


Joerg Sommer <joerg@xxxxxxxxxxxx> wrote:
>I ask myself often, what is the advantage of $1 or $2 (and so on) over a
>real variable with a name? Is there any?

They are pre-declared "convenience" variables.  With that said _never_
use them in functions.  slang has a number of optimizations that
involve local variables and relatively few involving global variables.
Here is a simple slsh experiment that illustrates this:

   slsh> define foo1 () { loop (10000000) $1 = $1-2*$1+3*$1-4*$1; }
   slsh> define foo (x) { loop (10000000) x = x-2*x+3*x-4*x; }     
   slsh> tic; foo(5);toc;                                          
   7.12571
   slsh> tic; $1=5; foo1();toc;                                    
   10.2782

This indicates that the version involving the local variable is about
30% faster.

--John

_______________________________________________
To unsubscribe, visit http://jedsoft.org/slang/mailinglists.html


[2005 date index] [2005 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]