Last active
December 21, 2015 06:49
-
-
Save epickrram/6267217 to your computer and use it in GitHub Desktop.
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 BigDecimalBenchmark extends SimpleBenchmark | |
{ | |
private static final BigDecimal QUANTITY_DIVISOR = new BigDecimal(100); | |
private static final BigDecimal PRICE_DIVISOR = new BigDecimal(1000000); | |
private static final BigDecimal QUANTITY_INCREMENT = new BigDecimal("0.001"); | |
private static final BigDecimal PRICE_INCREMENT = new BigDecimal("0.00001"); | |
@Override | |
protected void setUp() throws Exception | |
{ | |
} | |
public long timeQuantityDivisor(final int reps) | |
{ | |
int signum = 0; | |
for(int i = 0; i < reps; i++) | |
{ | |
signum += new BigDecimal(Math.abs(i)).divide(QUANTITY_DIVISOR).setScale(5).signum(); | |
} | |
return signum; | |
} | |
public long timePriceDivisor(final int reps) | |
{ | |
int signum = 0; | |
for(int i = 0; i < reps; i++) | |
{ | |
signum += new BigDecimal(i).divide(PRICE_DIVISOR).setScale(6).signum(); | |
} | |
return signum; | |
} | |
public long timeQuantityMultiplier(final int reps) | |
{ | |
int signum = 0; | |
for(int i = 0; i < reps; i++) | |
{ | |
signum += QUANTITY_INCREMENT.multiply(BigDecimal.valueOf(i)).signum(); | |
} | |
return signum; | |
} | |
public long timePriceMultiplier(final int reps) | |
{ | |
int signum = 0; | |
for(int i = 0; i < reps; i++) | |
{ | |
signum += PRICE_INCREMENT.multiply(BigDecimal.valueOf(i)).signum(); | |
} | |
return signum; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment