Some benchmarks
Posted: Sun Dec 01, 2013 11:13 am
' i used the following benchmark program to check the calculation speed of Smart Basic on some hardware here, including
' the new iPhone 5S. The program inverts a 20x20 matrix with random elements.
'
' The results are:
' iPhone 3GS : 630 msec. (milliseconds)
' iPad 1 : 515 msec.
' iPad 3 : 235 msec.
' iPhone 5S. : 60 msec.
'
' using a pure graphics program (automaton) the 5S is also about 10 times faster than the 3GS.
'
option base 1 ! sz=20
dim ma(sz,sz),mi(sz,sz)
mat_rnd (sz,sz,ma,-10,10)
timer reset
mat_inv (sz,ma,mi)
print timer()
end
' produce a matrix with random elements between mini and maxi
'
def mat_rnd (n,m,mat(,),mini,maxi)
for i=1 to n
for j=1 to m ! mat(i,j)=mini+(maxi-mini)*rnd(1) ! next j
next i
end def
' produce the inverse of square matrix a() giving matrix ainv()
'
def mat_inv (nvar,a(,),ainv(,))
dim w(nvar,2*nvar)
for i=1 to nvar
for j=1 to nvar ! w(i,j)=a(i,j) ! w(i,j+nvar)=0 ! next j
w(i,i+nvar)=1
next i
for piv=1 to nvar
fac=w(piv,piv)
for j=piv to piv+nvar ! w(piv,j)=w(piv,j)/fac ! next j
for i=1 to nvar
if i<>piv then
fac=w(i,piv)
for j=piv to piv+nvar ! w(i,j)=w(i,j)-fac*w(piv,j) ! next j
endif
next i
next piv
for i=1 to nvar
for j=1 to nvar ! ainv(i,j)=w(i,j+nvar) ! next j
next i
end def
' the new iPhone 5S. The program inverts a 20x20 matrix with random elements.
'
' The results are:
' iPhone 3GS : 630 msec. (milliseconds)
' iPad 1 : 515 msec.
' iPad 3 : 235 msec.
' iPhone 5S. : 60 msec.
'
' using a pure graphics program (automaton) the 5S is also about 10 times faster than the 3GS.
'
option base 1 ! sz=20
dim ma(sz,sz),mi(sz,sz)
mat_rnd (sz,sz,ma,-10,10)
timer reset
mat_inv (sz,ma,mi)
print timer()
end
' produce a matrix with random elements between mini and maxi
'
def mat_rnd (n,m,mat(,),mini,maxi)
for i=1 to n
for j=1 to m ! mat(i,j)=mini+(maxi-mini)*rnd(1) ! next j
next i
end def
' produce the inverse of square matrix a() giving matrix ainv()
'
def mat_inv (nvar,a(,),ainv(,))
dim w(nvar,2*nvar)
for i=1 to nvar
for j=1 to nvar ! w(i,j)=a(i,j) ! w(i,j+nvar)=0 ! next j
w(i,i+nvar)=1
next i
for piv=1 to nvar
fac=w(piv,piv)
for j=piv to piv+nvar ! w(piv,j)=w(piv,j)/fac ! next j
for i=1 to nvar
if i<>piv then
fac=w(i,piv)
for j=piv to piv+nvar ! w(i,j)=w(i,j)-fac*w(piv,j) ! next j
endif
next i
next piv
for i=1 to nvar
for j=1 to nvar ! ainv(i,j)=w(i,j+nvar) ! next j
next i
end def