Skip to content

Instantly share code, notes, and snippets.

@epickrram
Last active December 21, 2015 06:49
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 epickrram/6267217 to your computer and use it in GitHub Desktop.
Save epickrram/6267217 to your computer and use it in GitHub Desktop.
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