Paste: Basic struct bench
Author: | alban |
Mode: | factor |
Date: | Mon, 31 Aug 2009 10:42:39 |
Plain Text |
; Basic struct bench
Macro Max(a, b)
(((Not a>b) * b )+((Not a<b) *a ))
EndMacro
#len = 5000000
Structure pointXYZ
x.d
y.d
z.d
EndStructure
NewList Points.pointXYZ()
t1 = ElapsedMilliseconds()
; init
aPoint.pointXYZ
For i=0 To #len
AddElement( Points())
Points()\x=Sin(i)
Points()\y=Cos(i)*3.0
s.d=Sin(i)
Points()\z=(s*s)/2.0
Next
; normalize
ForEach Points()
norm.d=Sqr( (Points()\x * Points()\x )+ (Points()\y * Points()\y ) + (Points()\z * Points()\z))
Points()\x = Points()\x / norm
Points()\y = Points()\y / norm
Points()\z = Points()\z / norm
Next
; find max
ForEach Points()
aPoint\x = max( aPoint\x, Points()\x)
aPoint\y = max( aPoint\y, Points()\y)
aPoint\z = max( aPoint\z, Points()\z)
Next
;print result
t2 = ElapsedMilliseconds()-t1
Debug StrD(aPoint\x)+" "+StrD(aPoint\y)+" "+StrD(aPoint\z)+" "+Str(t2)+" ms"
;About 4.5 seconds on a MacBook 2.4Ghz, Vista.
;list feels more idiomatic than an array.
New Annotation