Created
February 9, 2016 11:17
-
-
Save c0rp-aubakirov/fd797307ff5668d618ec to your computer and use it in GitHub Desktop.
Test what is faster: comparing big decimals or cast to int and compare
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
@Test | |
public void testBigDecimal() throws Exception { | |
final SecureRandom random = new SecureRandom(); | |
for (int j = 0; j < 30; j++) { | |
Timer.executeFunctionWithTimer(() -> { | |
int value = 0; | |
for (int i = 0; i < 1000000; i++) { | |
value = new BigDecimal(random.nextInt()).intValueExact(); | |
} | |
return value > 10; | |
}); | |
Timer.executeFunctionWithTimer(() -> { | |
BigDecimal value = null; | |
for (int i = 0; i < 1000000; i++) { | |
value = new BigDecimal(random.nextInt()); | |
} | |
return value.compareTo(BigDecimal.TEN); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment