[OT] RE: counter++ versus "add 1 to counter"

Brian Yennie briany at qldlearning.com
Thu Mar 25 01:09:31 EST 2004


> was something like:
>
> put 1 into c
> repeat for 100000000
>   add 2 to c
> end repeat
>
> I don't have the c++ source

Very cool- a big applause for Rev. My C++ instincts would tell me, just 
like your friend, that running that tight of a mathematical loop in an 
interpreted language might be much more than 7 times slower.

But not in Rev =)!

FWIW, the equivalent C++ would be something like:

int c = 1;
for(int i=0; i<100000000;i++) i += 2;

Of course, the compiler might make a big difference- some compilers may 
be smart enough to effectively optimize that loop to become the same as:

int c = 1;
i += 200000000;

Speaking of which, has anyone ever considered writing an optimizer for 
Transcript, that does basic stuff like unrolling loops, killing dead 
branches, etc? It would probably even be possible to pre-process 
scripts to make sure they use "repeat for each" when necessary, and 
other much-discussed optimizations.

- Brian



More information about the use-livecode mailing list