Created
July 7, 2020 17:47
-
-
Save pfrozi/d0bfe928ad9fc14cd8fbc207e45d47e1 to your computer and use it in GitHub Desktop.
test StringBuilder
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
int size = 100000; | |
long start; | |
List<string> list = new List<string>(size); | |
for(var i = 0; i < size; i++) | |
list.Add($"string_{i}"); | |
Console.WriteLine("Aggregate string:"); | |
start = DateTime.Now.Ticks; | |
list.Aggregate("", (a, b) => a + "," + b); | |
Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start)); | |
Console.WriteLine("Join:"); | |
start = DateTime.Now.Ticks; | |
string.Join(",", list); | |
Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start)); | |
Console.WriteLine("Aggregate StringBuilder:"); | |
start = DateTime.Now.Ticks; | |
list.Aggregate(new StringBuilder(""), (a, b) => a.Append(",").Append(b)); | |
Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start)); | |
Console.WriteLine("Aggregate $:"); | |
start = DateTime.Now.Ticks; | |
list.Aggregate("", (a, b) => $"{a},{b}"); | |
Console.WriteLine(new TimeSpan(DateTime.Now.Ticks - start)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment