Created
March 21, 2012 18:16
-
-
Save ctrueden/2150639 to your computer and use it in GitHub Desktop.
Comparing RealPoint constructor implementations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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