Created
January 9, 2012 18:51
DoubleVsBigDecimalBenchmark
This file contains 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
public class DoubleVsBigDecimalBenchmark extends SimpleBenchmark { | |
@Param({"1", "1.01", "1.0123456789", "20", "20.01", "20.0123456789", "1000000000", "1000000000.01", "1000000000.0123456789"}) | |
private double value; | |
private BigDecimal[] bigDecimalVal = new BigDecimal[1]; | |
private double[] doubleVal = new double[1]; | |
@Override | |
protected void setUp() throws Exception { | |
bigDecimalVal[0] = BigDecimal.valueOf(value); | |
doubleVal[0] = value; | |
} | |
public void timeDouble(int reps) { | |
double dummy = 0; | |
for (int i = 0; i < reps; i++) { | |
int v = i / (reps + 1); | |
dummy = doubleVal[v] * doubleVal[v]; | |
} | |
doubleVal[0] = dummy; | |
} | |
public void timeBigDecimal(int reps) { | |
BigDecimal dummy = BigDecimal.ZERO; | |
for (int i = 0; i < reps; i++) { | |
int v = i / (reps + 1); | |
dummy = bigDecimalVal[v].multiply(bigDecimalVal[v]); | |
} | |
bigDecimalVal[0] = dummy; | |
} | |
public static void main(String[] args) { | |
Runner.main(DoubleVsBigDecimalBenchmark.class, new String[]{}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment