Last active
February 23, 2019 09:59
-
-
Save priesdelly/a3f315b117e395801ee1cca03c453caf to your computer and use it in GitHub Desktop.
Example use "System.Text.StringBuilder" in .NET framework by C# language
This file contains 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; | |
using System.Diagnostics; | |
using System.Text; | |
namespace StringBuilder | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
// ใช้ + ธรรมดาที่นิยมใช้กัน | |
Stopwatch sw1 = new Stopwatch(); | |
string fooString1 = String.Empty; | |
sw1.Start(); | |
for (int i = 0; i < 10000; i++) | |
{ | |
fooString1 += i.ToString(); | |
} | |
sw1.Stop(); | |
string sw1time = sw1.ElapsedMilliseconds; | |
Console.WriteLine("[Normal] Process time : " + sw1time + " ms."); | |
// ใช้ Append ของ StringBuilder | |
Stopwatch sw2 = new Stopwatch(); | |
StringBuilder fooString2 = new StringBuilder(); | |
sw2.Start(); | |
for (int i = 0; i < 10000; i++) | |
{ | |
fooString2.Append(i.ToString()); | |
} | |
sw2.Stop(); | |
string sw2time = sw2.ElapsedMilliseconds; | |
Console.WriteLine("[StringBuilder] Process time : " + sw2time + " ms."); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment