Re: Structures; etc.

new topic     » goto parent     » topic index » view thread      » older message » newer message

EU>On Sun, 30 Jan 2000, you wrote:
EU>> I think the best way to go would be to use a pre-processor. This would
EU>> allow the interpreter to stay small and fast, and it would not require
EU>> any modification. It would also let people choose from a variety of
EU>> pre-processors, or write one themselves, so they can decide on the style
EU>> they like.

EU>Pretty much out of the question - we would still be using the type() functio
EU>Try this program:

EU>atom start

EU>type byte (object x)
EU> if x < 0 or x > 255 then return 0
EU> else return 1
EU> end if
EU>end type

EU>byte x

EU>start = time()
EU>for i = 1 to 10000000 do
EU>  x = 5
EU>end for
EU>? time() - start  -- takes avg. 4.51 seconds

EU>integer y

EU>start = time()
EU>for i = 1 to 10000000 do
EU>   y = 5
EU>end for
EU>? time() - start -- takes avg. 0.54 seconds

EU>You can see that user-defined types are useless except for debugging purpose
EU>as the overhead kills any performance whatsoever.  This is for a single type
EU>check. I haven't even tried nested type checks. Any pre-processor would eith
EU>have to let everything go untyped, or rely on the type() function. Neither i
EU>acceptable. This functionality needs to be built into the language itself.

EU>Irv

How would building object-orientation into the interpreter make this go
faster? A pre-processor could be smart, and not do unnessicary type
checking. For example:

type sequenceOfIntegers(object x)
        if sequence(x) then
                for i = 1 to length(x) do
                        if not integer(x[i]) then
                                return 0
                        end if
                end for
                return 1
        end if
        return 0
end type

class MyClass
        sequenceOfIntegers seq1
        sequenceOfIntegers seq2
        sequenceOfIntegers seq3
        sequenceOfIntegers seq4
        sequenceOfIntegers seq5
end class

MyClass instance
instance.seq1 = repeat(0,100000)
instance.seq2 = instance.seq1
instance.seq3 = instance.seq1
instance.seq4 = instance.seq1
instance.seq5 = instance.seq1
instance.seq5[50] = 1000

A smart pre-processor could optomize see that:
1. When instance.seq1 and instance.seq5[50] are assigned, there is no need to
check everything else.
2. When instance.seq2-5 are assigned, there is no need to check them
because instance.seq1 is the same type and they're ok

In your example, a smart pre-processor could see that 5 is a byte, and
therefore x doesn't need to be checked 10000000. In fact, an even
smarter pre-processor could optomize the code to:

byte x
atom start
start = time()
x = 5
? time()-start

or:

without type_check      -- It knows there won't be any type checking
                        -- errors
integer x
atom start
start = time()
x = 5                   -- It knows that 5 is a byte
? time()-start

What might increase speed a lot in some cases would be an array type.
This would allow something like:

integer bigArray[10000000]
bigArray[10000000] = 5

to only check bigArray[10000000] instead of:

sequenceOfIntegers bigArray
bigArray = repeat(0,10000000) -- Big type checking operation here
bigArray[10000000] = 5 -- Another big type checking operation

Jeff

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu