I recieved 2.594 seconds for ^2 and 0.172 seconds for n*n.
Code: Select all
Structure ptcoord
x.f
y.f
z.f
EndStructure
Procedure.f RndNeg(num)
n=Random(1)
i=Random(num)
If n=1
i=i*-1
EndIf
ProcedureReturn i
EndProcedure
Procedure.f Dist3d(x1.f,y1.f,z1.f,x2.f,y2.f,z2.f)
ProcedureReturn Sqr(Pow((x2.f-x1.f),2)+Pow((y2.f-y1.f),2)+Pow((z2.f-z1.f),2))
EndProcedure
Procedure.f Dist3d_2(x1.f,y1.f,z1.f,x2.f,y2.f,z2.f)
xd.f=(x2.f-x1.f)
yd.f=(y2.f-y1.f)
zd.f=(z2.f-z1.f)
dist.f=Sqr(xd.f*xd.f+yd.f*yd.f+zd.f*zd.f)
ProcedureReturn dist.f
EndProcedure
;50,000 points * 60 fps * 1 seconds
point_count.q=50000*60*1
Dim a.ptcoord(point_count)
time.f
For i=1 To point_count
a(i)\x=RndNeg(5000)/(Random(10)+1)
a(i)\y=RndNeg(5000)/(Random(10)+1)
a(i)\z=RndNeg(5000)/(Random(10)+1)
Next i
A_point.ptcoord
A_point\x=RndNeg(5000)/(Random(10)+1)
A_point\y=RndNeg(5000)/(Random(10)+1)
A_point\z=RndNeg(5000)/(Random(10)+1)
output.s="Considering "+Str(point_count)+" points"+Chr(10)+Chr(13)+Chr(10)+Chr(13)
start.f=ElapsedMilliseconds()
For i=1 To point_count
newdist.f=Dist3d(A_point\x,A_point\y,A_point\z,a(i)\x,a(i)\y,a(i)\z)
If newdist.f<closest.f Or closest.f=0
closest.f=newdist.f
EndIf
If newdist.f>farthest.f Or farthest.f=0
farthest.f=newdist.f
EndIf
Next i
time.f=(ElapsedMilliseconds()-start.f)/1000
output.s+"Euclidean distance (^2):"+Chr(10)+Chr(13)
output.s+"The closest point is "+StrF(closest.f)+Chr(10)+Chr(13)
output.s+"The farthest point is "+StrF(farthest.f)+Chr(10)+Chr(13)
output.s+"Completed in "+StrF(time.f)+" seconds."+Chr(10)+Chr(13)+Chr(10)+Chr(13)
start.f=ElapsedMilliseconds()
For i=1 To point_count
newdist.f=Dist3d_2(A_point\x,A_point\y,A_point\z,a(i)\x,a(i)\y,a(i)\z)
If newdist.f<closest.f Or closest.f=0
closest.f=newdist.f
EndIf
If newdist.f>farthest.f Or farthest.f=0
farthest.f=newdist.f
EndIf
Next i
time.f=(ElapsedMilliseconds()-start.f)/1000
output.s+"Euclidean distance (n*n):"+Chr(10)+Chr(13)
output.s+"The closest point is "+StrF(closest.f)+Chr(10)+Chr(13)
output.s+"The farthest point is "+StrF(farthest.f)+Chr(10)+Chr(13)
output.s+"Completed in "+StrF(time.f)+" seconds."+Chr(10)+Chr(13)+Chr(10)+Chr(13)
MessageRequester("",output.s)