class="java"> public class TimeCountUtil { private static long start = System.currentTimeMillis(); public static long init(){ return start; } public static long count(){ return System.currentTimeMillis()-init(); } }
public class Test{ public static void main(String[] args){ String s = ""; for(int i = 0;i<100000;i++){ TimeCountUtil.init(); s+="a"; } long result = TimeCountUtil.count(); System.out.println("共花时:"+result+"毫秒"); } }