同事写了一段牛逼的代码我以为这个是为了提升就像日志输出时候性能问题。但是在自己测试之后获得臆想不到的效果。
import java.text.MessageFormat; public class TestMessageFormmat { public static void main(String[] args) { String c; Long startFormat=System.currentTimeMillis(); for (int i=0;i<100000;i++) c=MessageFormat.format("{0}{1}","a","b"); Long endFormat=System.currentTimeMillis(); Long start=System.currentTimeMillis(); for (int i=0;i<100000;i++) c="a"+"b"; Long end=System.currentTimeMillis(); System.out.println("format time:"+(endFormat-startFormat)+" time:"+(end-start)); } }
测试后的结果,我以为我第二个时间是没有记录么,后来debug处理了一下。并不是。
format time:231 time:0