StringBuilder和StringBuffer append()相同字符所用时间及所占内存对比。
可以看到40万个字符串以内StringBuffer速度快一些,40万以上StringBuilder快一些。
内存占用方面,千万级差距会大一些。
----------------------------------------------------------------------------------------------
The Max memory: 4066M
Loop times:10000
StringBuilder Time of StringBuilder excute:2ms
StringBuilder Memory of StringBuilder consume:1M
StringBuffer Time of StringBuffer excute:1ms
StringBuffer Memory of StringBuffer consume:1M
Loop times:100000
StringBuilder Time of StringBuilder excute:5ms
StringBuilder Memory of StringBuilder consume:1M
StringBuffer Time of StringBuffer excute:6ms
StringBuffer Memory of StringBuffer consume:1M
Loop times:300000
StringBuilder Time of StringBuilder excute:7ms
StringBuilder Memory of StringBuilder consume:3M
StringBuffer Time of StringBuffer excute:3ms
StringBuffer Memory of StringBuffer consume:4M</