Skip to content

Instantly share code, notes, and snippets.

@ctrueden
Created March 21, 2012 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctrueden/2150639 to your computer and use it in GitHub Desktop.
Save ctrueden/2150639 to your computer and use it in GitHub Desktop.
Comparing RealPoint constructor implementations
//
// ConstructorPerformance.java
//
public class ConstructorPerformance {
public static double x = 1, y = 2, z = 3;
public static void main(final String[] args) throws Exception {
final int iter = 10000000;
System.out.print("Timing RealPoint... ");
final long start = System.currentTimeMillis();
for (int i = 0; i < iter; i++) {
new RealPointSS(x, y, z);
// new RealPointCR(x, y, z);
}
final long end = System.currentTimeMillis();
System.out.println((end - start) + " ms elapsed");
}
public static class RealPointSS {
private final double[] pos;
public RealPointSS(final double... position) {
pos = position.clone();
}
}
public static class RealPointCR {
private final double[] pos;
public RealPointCR(final double... position) {
this(position, true);
}
protected RealPointCR(final double[] position, final boolean copy) {
pos = copy ? position.clone() : position;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment