Java benchmarking - why is the second loop faster?
问题 I'm curious about this. I wanted to check which function was faster, so I create a little code and I executed a lot of times. public static void main(String[] args) { long ts; String c = "sgfrt34tdfg34"; ts = System.currentTimeMillis(); for (int k = 0; k < 10000000; k++) { c.getBytes(); } System.out.println("t1->" + (System.currentTimeMillis() - ts)); ts = System.currentTimeMillis(); for (int i = 0; i < 10000000; i++) { Bytes.toBytes(c); } System.out.println("t2->" + (System.currentTimeMillis