Created
April 23, 2020 22:55
-
-
Save mehmetcantas/ffe642cf52cd84e735871b0fd658e455 to your computer and use it in GitHub Desktop.
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
class Program | |
{ | |
const int limit = 300000; | |
static void Main(string[] args) | |
{ | |
var plusOperatorResult = WithPlusOperator(); | |
var stringBuildeResult = WithStringBuilder(); | |
Console.WriteLine("Plus Operator Result : " + plusOperatorResult); | |
Console.WriteLine("String Builder Result : " + stringBuildeResult); | |
Console.ReadLine(); | |
} | |
static long WithPlusOperator() | |
{ | |
string variable = ""; | |
Stopwatch watch = new Stopwatch(); | |
watch.Start(); | |
for (int i = 0; i < limit; i++) | |
{ | |
variable += "x"; | |
} | |
watch.Stop(); | |
return watch.ElapsedMilliseconds; | |
} | |
static long WithStringBuilder() | |
{ | |
StringBuilder builder = new StringBuilder(); | |
Stopwatch watch = new Stopwatch(); | |
watch.Start(); | |
for (int i = 0; i < limit; i++) | |
{ | |
builder.Append("x"); | |
} | |
watch.Stop(); | |
return watch.ElapsedMilliseconds; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment