[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Whetstone and Dhrystone on Lua
- From: "Mauro Iazzi" <mauro.iazzi@...>
- Date: Tue, 11 Mar 2008 13:39:56 +0100
I have modified the whetstone benchmark to make use of locals.
the speed at least doubles here.
However, you can find somewhere a whitepaper on the history of Lua. it
shows clearly that fibonacci benchmarks get worse at each new version.
Similarly you can expect that heavy integer arithmetics is the worst
field of comparison for Lua, since it is developed with other purposes
in mind.
cheers,
mauro
------ whet.lua
local e1 = {}
local j
local t, t1, t2, Loop, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11,
x1, x2, x3, x4
local x, y, z, j, k, l
function pa(e)
local 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)/clock();
print("Tempo di esecuzione: "..clock())
print("Utilizzo memoria: "..gcinfo().." Kbyte")
print("Kwips (kilo-Whetstone Instructions per seconds): "..Kips)
-------- end of whet.lua
you may find this useful, invoke as lua bench.lua script.lua
--------- bench.lua
local filename = (...) or error'script missing'
local cmd = [[lua -lstrict -e'clock=os.clock' ]] .. filename
local out = {}
local res_t = {}
local res_m = {}
local res_s = {}
run = function()
local f = io.popen(cmd)
local l, i = f:read(), 1
while l do
if i<11 then
out[i] = out[i] or l
if out[i]~=l then
io.write(out[i])
io.write(l)
error'outputs don\'t match'
end
elseif
i==11 then
local r = string.match(l, '^Tempo di
esecuzione: ([%d.]+)$') or error(l)
r = tonumber(r)
table.insert(res_t, r)
elseif
i==12 then
local r = string.match(l, '^Utilizzo memoria:
([%d.]+) Kbyte$') or error(l)
r = tonumber(r)
table.insert(res_m, r)
elseif
i==13 then
local r = string.match(l, '^Kwips
%(kilo%-Whetstone Instructions per seconds%): ([%d.]+)$') or error(l)
r = tonumber(r)
table.insert(res_s, r)
end
l, i =
f:read(), i+1
end
end
local nrun = 10
for i=1,nrun do
io.write('\rrun
'..tostring(i)..'/'..tostring(nrun))
run()
end
print()
mean = function(t)
local ret, n = 0, 0
for i, v in ipairs(t) do
ret =
ret + tonumber(v)
n = i
end
return ret/n
end
deviations = function(t, m)
local ret = {}
for i, v in ipairs(t) do
ret[i] = (v-m)^2
end
return ret
end
print('time', mean(res_t), '+-', mean(deviations(res_t, mean(res_t))))
print('mem', mean(res_m), '+-', mean(deviations(res_m, mean(res_m))))
print('speed', mean(res_s), '+-', mean(deviations(res_s, mean(res_s))))
------ end of bench.lua
On 11/03/2008, Armando Arleo <misterwhite81@yahoo.it> wrote:
> I think there has been a misunderstanding...I didn't mean to offend anybody.
> I'm new to this mailing list and I apologise for my behaviour.
> I know that I'm a newbie in using Lua that's why I asked for help.
> I've tried the hints that people gave me yesterday and now I'm checking the
> website you've suggested to me.
> I'm also tryin' modifing the code I wrote using local variables and I've
> installed LuaJit
> I will keep you updated on my next results
> Thanks a lot
> Armando Arleo
>
>
>
>
> KHMan <keinhong@gmail.com> ha scritto:
> Mister White wrote:
> >
> > :-)
> > I'm tryin' to write benchmark for a university dissertation and when I
> > showed my results to my teacher he has told me: "Try posting something
> > on forums or mailing lists asking for help and after everybody has
> > offended you lots of times there will be someone who will give you a
> > real help!"
> > So it shall be written so it shall be done!
> > :-)
> >
> >
>
> Mike Pall has pointed you to the right direction:
> http://shootout.alioth.debian.org/
>
> And see this also:
> http://lua-users.org/wiki/OptimisationCodingTips
>
> You need to understand a lot more about scripting languages like
> Lua and how they are implemented, in order to devise, run, and
> analyze useful benchmarks. Using those performance tips without
> proper understanding will be meaningless, thus you have a lot to
> study. All the more important since you claim to be doing a
> dissertation.
>
> You'd also be treated with a lot more respect, less suspicion, and
> less hostility if you use your real name. As it stands, I for one
> do not believe your above response at all; a university student
> would likely treat the list with more respect and less flippantly.
>
> Please show us that you are worth our time responding to and
> you'll get all the help you need. If you don't, you'll likely be
> ignored. The Lua list is usually a nice mailing list; I won't
> continue discussing this thread anymore.
>
> > */Miles Bader /* ha scritto:
> > [snipped]
> > "Wim Couwenberg" writes:
> > > Please address others on this list with some respect.
>
> --
> Cheers,
> Kein-Hong Man (esq.)
> Kuala Lumpur, Malaysia
>
>
>
> ________________________________
> Inviato da Yahoo! Mail.
> La web mail più usata al mondo.