日期:2014-05-20 浏览次数:20711 次
ublic class CompareStringNothing {
String s = "";
long n = 10000000;
private void function1() {
long startTime = System.currentTimeMillis();
for(long i = 0; i < n; i++) {
if(s == null || s.equals(""));
}
long endTime = System.currentTimeMillis();
System.out.println("function 1 use time: "+ (endTime - startTime) +"ms");
}
private void function2() {
long startTime = System.currentTimeMillis();
for(long i = 0; i < n; i++) {
if(s == null || s.length() <= 0);
}
long endTime = System.currentTimeMillis();
System.out.println("function 2 use time: "+ (endTime - startTime) +"ms");
}
private void function3() {
long startTime = System.currentTimeMillis();
for(long i = 0; i < n; i++) {
if(s == null || s.isEmpty());
}
long endTime = System.currentTimeMillis();
System.out.println("function 3 use time: "+ (endTime - startTime) +"ms");
}
public static void main(String[] args) {
CompareStringNothing com = new CompareStringNothing();
com.function1();
com.function2();
com.function3();
}
}