Skip to content

Instantly share code, notes, and snippets.

@mairbek
Created January 9, 2012 18:51
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 mairbek/1584324 to your computer and use it in GitHub Desktop.
Save mairbek/1584324 to your computer and use it in GitHub Desktop.
DoubleVsBigDecimalBenchmark
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