Paste: struct array benchmark -- java version
| Author: | slava |
| Mode: | java |
| Date: | Fri, 28 Aug 2009 09:19:32 |
Plain Text |
public class silly
{
static class Point
{
float x, y, z;
Point() { }
Point(int n)
{
this.x = (float)Math.sin(n);
this.y = (float)Math.cos(n) * 3;
double s = Math.sin(n);
this.z = (float)((s * s) / 2);
}
double pointNorm()
{
return Math.sqrt(x * x + y * y + z * z);
}
void normalizePoint()
{
double norm = pointNorm();
x /= norm;
y /= norm;
z /= norm;
}
void maxPoint(Point p)
{
x = Math.max(x,p.x);
y = Math.max(y,p.y);
z = Math.max(z,p.z);
}
public String toString()
{
return x + ", " + y + ", " + z;
}
}
static Point[] makePoints(int len)
{
Point[] points = new Point[len];
for(int i = 0; i < len; i++)
points[i] = new Point(i);
return points;
}
static void normalizePoints(Point[] points)
{
for(int i = 0; i < points.length; i++)
points[i].normalizePoint();
}
static Point maxPoints(Point[] points)
{
Point max = new Point();
for(int i = 0; i < points.length; i++)
max.maxPoint(points[i]);
return max;
}
static void benchmark(int len)
{
Point[] points = makePoints(len);
normalizePoints(points);
System.out.println(maxPoints(points));
}
public static void main(String[] args)
{
for(int i = 0; i < 8; i++)
{
System.out.println("Run #" + i);
long start = System.currentTimeMillis();
benchmark(5000000);
long end = System.currentTimeMillis();
System.out.println("Time: " + (end - start));
}
}
}
New Annotation