2020.09.24 기초 자바 프로그래밍 효율성 체크

package i_api;


public class StringSpeedTest {


public static void main(String[] args) {

// TODO Auto-generated method stub

        

String str = "a"; 

        

long start = System.currentTimeMillis();

        for(int i = 0; i < 200000; i++){ 

        str += "a"; 

        }

            

        long end = System.currentTimeMillis();

System.out.println(end - start + "ms"); 



StringBuffer sb = new StringBuffer("a"); 

long start_ = System.currentTimeMillis(); 

for(int i = 0 ; i < 200000 ; i++){ 

sb.append("a"); 

}

long end_ = System.currentTimeMillis();

System.out.println(end - start + "ms"); 

}


}


댓글