Monday, May 2, 2011

Comparision in Java

Consider the case in which >, == and >= operator are used for comparison.

long starttime = System.currentTimeMillis();
for (int i = 0; i < 8888888; i++) {
if (i == 10 || i < 10) {

}
}
System.out.println(“Total time taken case1″+(System.currentTimeMillis()-starttime));

starttime = System.currentTimeMillis();
for (int i = 0; i < 8888888; i++) {
if (i <= 10) {

}
}
System.out.println(“Total time taken case2″+(System.currentTimeMillis()-starttime));

Output is :
Total time taken case1 31ms
Total time taken case2 16ms

Just try to use code efficiently.

No comments:

Post a Comment

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...