nutzam/ssdb4j — pull request #5 by yangwf (2014-05-29 03:24:47+00:00)
Title: 整数转字符串效率

整数num转成字符串，方式一：new
Integer(num).toString();方式二：num+"";方式一比方式二效率高40%以上（在PC上测试）。例子如下：
public static void main(String[] agrs) throws Exception{
long a = numToStr(true);
long b = numToStr(false);
System.out.println(new DecimalFormat("##.00%").format((b - a)*1.0f/b));
}
private static long numToStr(boolean flag){
String s = null;
Random rand = new Random();
int tem = 0;
long d = System.currentTimeMillis();
for(int i = 0; i < 1000000; i++){
tem = rand.nextInt(100000);
if(flag){
s = new Integer(tem).toString();
}else{
s = tem+"";
}
}
d = System.currentTimeMillis() - d;
if(flag){
System.out.println("toString方式 " + d);
}else{
System.out.println("连接方式 "+ d);
}
return d;
}