lua-users home
lua-l archive

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


I post the whetstone source code:
e1 = {}

function pa(e)
    j = 1
    repeat
       
        e[1] = (e[1] + e[2] + e[3] - e[4]) *t       
        e[2] = (e[1] + e[2] -e[3] +e[4]) *t
        e[3] = (e[1]-e[2]+e[3]+e[4])*t
        e[4] = (-e[1] + e[2] +e[3] + e[4])/t2
        j = j + 1;       
       
       
    until j <= 6 --cambiato goto in quanto il lua non supporta questo statement
end

function p0()

    e1[j] = e1[k]
    e1[k] = e1[l]
    e1[l] = e1[j]
       
end

function p3(x, y, z)
   
    local x1 = x
    local y1 = y
   
    x1 = t*(x1+y1)
    y1 = t*(x1+y1)
    z = (x1+y1)/t2
   
    return z   
end

function pout(n, j, k, x1, x2, x3, x4)
    print(string.format("%7d/%7d/%7d/%12.4e/%12.4e/%12.4e/%12.4e", n, j, k, x1, x2, x3, x4))
end

--inizializzazione costanti

t = 0.499975
t1 = 0.50025
t2  = 2.0

--Se Loop = 10 il peso totale è di un milione di istruzione Whetstone

Loop = 1000
n1 = 0
n2 = 12 * Loop
n3 = 14 * Loop
n4 = 345 * Loop
n5 = 0
n6 = 210 * Loop
n7 = 32 * Loop
n8 = 899 * Loop
n9 = 616 * Loop
n10 = 0
n11 = 93 * Loop

--modulo 1: ideficatori semplici
x1 = 1.0
x2 = -1.0
x3 = -1.0
x4 = -1.0

for i=1, n1 do
    x1 = (x1+ x2 + x3 + x4) * t
    x2 = (x1 + x2 - x3 + x4) * t
    x3 = (x1 - x2 + x3 + x4) *t
    x4 = (-x1 + x2 + x3+ x4)*t
end
--fine modulo 1

pout(n1,n1,n1,x1,x2,x3,x4)

-- modulo 2: elementi di array

e1[1] = 1.0

e1[2]= -1.000000
 e1[3] = -1.000000
  e1[4] = -1.00000

for i=1, n2 do
    e1[1] = (e1[1] + e1[2] + e1[3] - e1[4]) *t
    e1[1] = (e1[1] + e1[2] - e1[3] + e1[4]) *t
    e1[1] = (e1[1] - e1[2] + e1[3] + e1[4]) *t
    e1[1] = (-e1[1] + e1[2] + e1[3] + e1[4]) *t
end

--fine modulo 2

pout(n2, n3, n2, e1[1], e1[2], e1[3], e1[4])


--modulo 3: array come parametri

for i=1, n3 do   
    pa(e1)
end

pout(n3,n2,n2,e1[1],e1[2],e1[3], e1[4])

--modulo 4: salti condizionati

j=1

for i=1, n4 do
   
    if j==1 then
        j=2
    else
        j=3
    end
   
    if j>2 then
        j=0
    else
        j=1
    end
   
    if j<1 then
        j=1
    else
        j=0
    end
end
--fine modulo 4

pout(n4, j, j, x1, x2, x3, x4)

--modulo 5: omesso
--modulo 6: aritmetica di interi

j = 1
k = 2
l = 3

for i = 1, n6 do
    j = j*(k-j)*(l-k)
    k = l*k - (l-j) * k
    l = (l-k) * (k+j)
    e1[l-1] = j+k+l
    e1[k-1] = j*k*l
end

--fine modulo 6

pout(n6, j, k, e1[1], e1[2], e1[3], e1[4])

--modulo 7: funzioni trigonometriche

x = 0.5
y = 0.5

for i = 1, n7 do
    x = t*math.atan(t2 * math.sin(x) * math.cos(x)/(math.cos(x*y) + math.cos(x-y) - 1.0))
    y = t*math.atan(t2 * math.sin(y) * math.cos(y)/(math.cos(x+y) + math.cos(x-y) - 1.0))
end

pout(n7, j,k,x,x,y,y)

--modulo 8: chiamata a procedure

x = 1.0
 y = 1.0
  z = 1.0

for i=1, n1 do
    z = p3(x,y,z)
end
--fine modulo 8
pout(n8,j,k,x,y,z,z)

--modulo 9: riferimenti ad array

j=1
k=2
l=3
e1[1] = 1.0
e1[2] = 2.0
e1[3] = 3.0

for i=1, n9 do
    p0()
end

pout(n9,j,k,e1[1],e1[2],e1[3],e1[4])
--fine modulo 9

--modulo 10: aritmetica di interi

j=2
k=3
for i=1, n10 do
    j = j+k
    k = j+k
    j = k-j
    k=k-j-j
end

pout(n10,j,k,x1,x2, x3, x4)

--fine modulo 10

--modulo 11: funzioni standard

x = 0.75
for i=1, n11 do
    x = math.sqrt(math.exp(math.log(x)/t1))
end

pout(n11,j,k,x,x, x, x)

--fine algoritmo
--KIPS = numero di volte che si esegue il whetstone/tempo impiegato;
Kips = (1*Loop)/os.clock();
print("Tempo di esecuzione: "..os.clock())
print("Utilizzo memoria: "..gcinfo().." Kbyte")
print("Kwips (kilo-Whetstone Instructions per seconds): "..Kips)






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.