Faraday cages ( was Re: staticy plastic tubs )

Chuck Guzis cclist at sydex.com
Sun Oct 22 12:17:00 CDT 2006

On 22 Oct 2006 at 11:53, Michael B. Brutman wrote:

> If the compiler used a length descriptor strings then the 
> implementations would be equivalent, and the compiler should have the 
> upper hand?

Well, I never said that "runtime implementation was equal".  As a 
matter of fact, if you look at my earlier messages, I kept driving 
home the idea of slow runtimes being the biggest culprit in the 
"compiler vs. interpreter".

But even assuming the same runtimes, is it possible to still make the 
case?  Yes, in the case where the number of cycles spent to perform 
an operation is large in comparison to the interpereter overhead.

Let's go back to that example of mine, D$=A$+B$+C$ and suppose that 
descriptor-cum-length is used in both the interpreter and compiler.

An interpreter that was smart enough to do this>

    <get length of A$>
    <add length of B$>
    <add length of C$>
    <allocate D$ to fit the above sum of lengths>
    <move A$ to D$>
    <move B$ to D$+the length of A$>
    <move C$ to D$+the length of B$+length of A$>

and a compiler that was dumb enough to generate:

    <get length of A$>
    <add length of B$>
    <allocate temp to the sum of lengths>
    <move A$ to temp1>
    <move B$ to temp1+length of A$>
    <get length of temp1>
    <add length of C$>
    <allocate temp2 to the sum of lengths>
    <move temp1 to temp2>
    <move C$ to temp2+length of C$>
    <allocate D$ to length of temp2>
    <move temp2 to D$>
    <free temp1>
    <free temp2>

would, in the case of longer strings, likely turn in the advantage of 
the interpreter--even though the run-time is the same.

To be fair, however, any interpreter smart enough to perform on-the-
fly optimization is going to take longer to interpret each statement. 
 And there is no reason that a compiler could be even smarter than 
the interpreter.

On the BASIC-to-P-code compiler I worked on, we spent an inordinate 
amount of time optimizing string handling, realizing that the bulk of 
our application base was going to be just that--manipulating strings. 
 And that is what we determined was the big difference between 
Microsoft compiled BASIC and our own--and why we were able to 
outperform it by a wide margin--even though MS was generating 
"native" 8080 code.


> The topic/question originally started as 'A compiler generally wins, 
> given all other things being equal'.
> One of the problems with the discussion is that if you include the 
> runtime for the compiler, then you basically can match anything an 
> interpreter can do at run time.  So the whole discussion might be moot, 
> and might just come down to 'my specific implementation of such and such 
> is better than yours.'
> Mike

More information about the cctalk mailing list