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

I guess not many people fall for 1st case but still i have seen code implemented using case 1.
Just a cautionary Tip.

Advertisements