public static void main(String[] args) { ArrayList<Long> l = new ArrayList<>(7500001); long start= System.currentTimeMillis(); for(int i =0 ; i < 5000000; i ++){ long now = new Date().getTime(); l.add(now); } System.out.println("new date cost [" + (System.currentTimeMillis()- start) + "] ms"); l.clear(); start= System.currentTimeMillis(); for(int i =0 ; i < 5000000; i ++){ long now = System.currentTimeMillis(); l.add(now); } System.out.println("System.currentTimeMillis cost [" + (System.currentTimeMillis()- start) + "] ms"); l.clear(); }
结果:
new date cost [1842] ms System.currentTimeMillis cost [391] ms
时间: 2024-11-06 23:08:21