//测试代码
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要好