lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


As I'm sure someone is going to jump in here and say at some point:

Use local variables. Global variable lookups have a slight overhead that adds up into a greater performance penalty as you hit them over and over, especially in loops. Your benchmarks aren't really showing what Lua can do if you're not using locals where they're needed.

Evan

On Mon, Mar 10, 2008 at 10:59 AM, Mister White <misterwhite81@yahoo.it> wrote:
Dhrystone source code:
LOOPS = 500000

Enumeration = {Ident1=0, Ident2=1, Ident3=2, Ident4=3, Ident5=4} --astrazione del tipo enum

--creo la struttura (come una coda)

Record = {}

function Record.new()

    return {PtrComp = 0, Discr = 0, EnumComp, IntComp, StringComp}

end
Coda = {}

function Proc0()
   
    Coda[1] = Record.new();
    Coda[2] = Record.new();
    Coda[1].PtrComp = 2
    Coda[1].Discr = Enumeration.Ident1
    Coda[1].EnumComp = Enumeration.Ident3
    Coda[1].IntComp = 40
    Coda[1].StringComp = "DHRYSTONE PROGRAM, SOME STRING"
    Coda[2].StringComp = "DHRYSTONE PROGRAM, SOME STRING"
    String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING"
   
    --creo la matrice 51x51
    Array1Glob = {}
    Array2Glob = {}
   
    for i=1, 51 do
        Array2Glob[i] = {}
        for j=1, 51 do
            Array2Glob[i][j] = 0;
        end
    end
   
    Array2Glob[8][7] = 10
   
    for i=1, LOOPS do
       
        Char1Glob, BoolGlob = Proc5()
         BoolLoc, Char2Glob = Proc4()
        IntLoc1 = 2
        IntLoc2 = 3
        String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING"
        EnumLoc = Enumeration.Ident2
       
        BoolGlob = not(Func2(String1Loc, String2Loc))
        while IntLoc1 < IntLoc2 do
            IntLoc3 = 5 * IntLoc1 - IntLoc2
            IntLoc3 = Proc7(IntLoc1, IntLoc2, IntLoc3)
            IntLoc1 = IntLoc1 + 1
        end
        Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3)
        Proc1(Coda)       
        for indice = 1, 2 do
            if(indice == 1) then CharIndex = 'A'
            else CharIndex = 'B' end
                if EnumLoc == Func1(CharIndex, 'C') then
                    EnumLoc = Proc6(Enumeration.Ident1, EnumLoc)
                   
                end
        end
                IntLoc2 = IntLoc2 * IntLoc1
                IntLoc1 = IntLoc2 / IntLoc3
                IntLoc2 = 7 * (IntLoc2 - IntLoc3) - IntLoc1;
                IntLoc1 = Proc2(IntLoc1)
    end
end

function Proc1(codaIn)
    codaIn[1].IntComp = 5
    codaIn[2].IntComp = codaIn[1].IntComp
    codaIn[2].PtrComp = codaIn[1].PtrComp
    codaIn[2].PtrComp = Proc3(codaIn[2].PtrComp)
   
    if codaIn[2].Discr == Enumeration.Ident1 then
        codaIn[2].IntComp = 6
        codaIn[2].EnumComp = Proc6(codaIn[1].EnumComp, codaIn[2].EnumComp)
        codaIn[2].PtrComp = Coda[1].PtrComp
        codaIn[2].IntComp = Proc7(codaIn[2].IntComp, 10, codaIn[2].IntComp)
    else
        codaIn[1] = codaIn[2]
    end
end

function Proc2(IntParIO)
    IntLoc = IntParIO + 10
    local EnumLocale
    while(true) do
        if(Char1Glob == "A") then
            IntLoc = IntLoc - 1
            IntParIO = IntLoc - IntGlob
            EnumLocale = Enumeration.Ident1
        end
       
        if EnumLocale == Enumeration.Ident1 then break; end
    end
    return IntParIO
end

function Proc3(PtrParOut)
   
    if Coda ~= nil then
        PtrParOut =  Coda[1].ptrComp
    else
        IntGlob = 100
    end
    Coda[1].IntComp = Proc7(10, IntGlob, Coda[1].IntComp)
    return PtrParOut
   
end

function Proc4()
   
    if Char1Glob == "A" then
        BoolLoc = true
    else
        BoolLoc = false
    end
    BoolLoc = BoolLoc or BoolGlob
    Char2Glob = "B"
    return BoolLoc, Char2Glob
end

function Proc5()
    return "A", false
end

function Proc6(EnumParIn, EnumParOut)
    EnumParOut = EnumParIn
   
    if not(Func3(EnumParIn)) then
        EnumParOut = Enumeration.Ident4
    end

    if EnumParIn == Enumeration.Ident1 then
        EnumParOut = Enumeration.Ident1
    elseif EnumParIn == Enumeration.Ident2 then
        if IntGlob > 100 then
            EnumParOut = Enumeration.Ident1
        else
            EnumParOut = Enumeration.Ident4
        end
    elseif EnumParIn == Enumeration.Ident3 then
        EnumParOut = Enumeration.Ident2
    elseif EnumParIn == Enumeration.Ident5 then
        EnumParOut = Enumeration.Ident3
    end
return EnumParOut
end

function Proc7(IntParI1, IntParI2, IntParOut)
IntLoc = IntParI1 + 2
IntParOut = IntParI2 + IntLoc
return IntParOut
end

function Proc8(Array1Par, Array2Par, IntParI1, IntParI2)

IntLoc = IntParI1 + 5
Array1Par[IntLoc] = IntParI2
Array1Par[IntLoc + 1] = Array1Par[IntLoc]
Array1Par[IntLoc + 30] = IntLoc

for IntIndex = IntLoc, IntLoc+2 do
    Array2Par[IntLoc][IntIndex] = IntLoc
end
   
Array2Par[IntLoc][IntLoc - 1] = Array2Par[IntLoc][IntLoc - 1] +1
Array2Par[IntLoc + 20][IntLoc] = Array1Par[IntLoc]
IntGlob = 5
end

function Func1(CharPar1, CharPar2)

    CharLoc1 = CharPar1
    CharLoc2 = CharLoc1
    if CharLoc2 ~= CharPar2 then
        return Enumeration.Ident1
    else
        return Enumeration.Ident2
    end   
end
   
function Func2(StrParI1, StrParI2)
    CharLoc = ''
    IntLoc =2
    while IntLoc<=2 do
        if Func1(StrParI1[IntLoc], StrParI2[IntLoc +1]) == Enumeration.Ident1 then
            CharLoc = "A"
            IntLoc = IntLoc +1
        end
        if CharLoc >= "W" and CharLoc <= "Z" then
            IntLoc = 7
        end
        if CharLoc == "X" then
            return true;
           
        else
            if StrParI1 > StrParI2 then
                IntLoc = IntLoc + 7
                return true
            else
                return false
            end
        end
    end
end

function Func3(EnumParIn)
    local EnumLocale = EnumParIn
    if EnumLocale == Enumeration.Ident3 then
        return true;
    end
    return false
end

Proc0()

I've deleted the verification prints but I can ensure you that everything is correct.
Any kind of suggestion would be appreciated.
Thanks a lot
Armando




Bruno Silvestre <brunoos@inf.puc-rio.br> ha scritto:
On Mon, Mar 10, 2008 at 11:47 AM, Rob Kendrick wrote:
>
> Remember that these benchmarks are pretty meaningless in and of
> themselves. Also remember that Java is most likely being JITed, and has
> an integer type, where neither of those is the case with stock Lua.

You can try "java -Xint" to run the Java's benchmarks with JIT
disabled (interpreted-only mode).

--
bruno


Inviato da Yahoo! Mail.
La web mail più usata al mondo.