Last active
April 9, 2019 16:40
-
-
Save soraphis/fc90d18f8264e1dcd2ce3a102530b553 to your computer and use it in GitHub Desktop.
Testing garbage allocation of strings and string concatenation in unity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text; | |
using NUnit.Framework; | |
using Unity.Profiling; | |
namespace Tests | |
{ | |
public class NewTestScript | |
{ | |
[Test] | |
public void NewTestScriptSimplePasses() | |
{ | |
string oldString, someString, aThirdString; | |
using (new ProfilerMarker("MySystem.NewString").Auto()) | |
{ | |
someString = "0123456789"; | |
} | |
using (new ProfilerMarker("MySystem.StringConcat").Auto()) | |
{ | |
oldString = "01234" + "56789"; | |
} | |
someString = "012345"; | |
using (new ProfilerMarker("MySystem.StringConcat2").Auto()) | |
{ | |
oldString = someString + someString.Substring(0, 4); | |
} | |
someString = "01234"; | |
oldString = "56789"; | |
using (new ProfilerMarker("MySystem.StringConcat3").Auto()) | |
{ | |
aThirdString = someString + oldString; | |
} | |
StringBuilder builder = new StringBuilder(64); // make sure its large enough | |
using (new ProfilerMarker("MySystem.BuilderAppend").Auto()) | |
{ | |
builder.Append("0123456789"); | |
} | |
using (new ProfilerMarker("MySystem.BuilderAppend2").Auto()) | |
{ | |
builder.Append("0123456789"); | |
} | |
using (new ProfilerMarker("MySystem.BuilderAppendLine").Auto()) | |
{ | |
builder.AppendLine("0123456789"); | |
} | |
using (new ProfilerMarker("MySystem.BuilderClear").Auto()) | |
{ | |
builder.Clear(); | |
} | |
using (new ProfilerMarker("MySystem.BuilderAppendAC").Auto()) | |
{ | |
builder.Append("0123456789"); | |
} | |
using (new ProfilerMarker("MySystem.BuilderAppend2AC").Auto()) | |
{ | |
builder.Append("0123456789"); | |
} | |
using (new ProfilerMarker("MySystem.BuilderAppendLineAC").Auto()) | |
{ | |
builder.AppendLine("0123456789"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment