StringBuilder 清除性能对比
作者:互联网
//测试代码
StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < 100; i++) { stringBuilder.Append(i); } Profiler.BeginSample("Clear"); stringBuilder.Clear(); Debug.Log(stringBuilder.ToString()); Profiler.EndSample(); for (int i = 0; i < 100; i++) { stringBuilder.Append(i); } Profiler.BeginSample("Remove"); stringBuilder.Remove(0, stringBuilder.Length); Debug.Log(stringBuilder.ToString()); Profiler.EndSample(); for (int i = 0; i < 100; i++) { stringBuilder.Append(i); } Profiler.BeginSample("Length"); stringBuilder.Length = 0; Debug.Log(stringBuilder.ToString()); Profiler.EndSample();
Remove Lenght 效率和GC比Clear要好
标签:清除,Log,int,StringBuilder,Profiler,BeginSample,stringBuilder,对比 来源: https://www.cnblogs.com/foxzhou89/p/15733007.html