Created
October 24, 2011 09:34
-
-
Save SimonCropp/1308672 to your computer and use it in GitHub Desktop.
string concat tests
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
[TestFixture] | |
public class TestStringMethods | |
{ | |
string bar = "Sdfsdf"; | |
int reps = 1000000; | |
string foo = "dsfsd"; | |
[Test] | |
public void Format() | |
{ | |
var format1 = String.Format("My {0} likes to eat {1}", foo, bar); | |
var startNew = Stopwatch.StartNew(); | |
for (var i = 0; i < 1000000; i++) | |
{ | |
var format = String.Format("My {0} likes to eat {1}", foo, bar); | |
} | |
startNew.Stop(); | |
var time = ((double)startNew.ElapsedMilliseconds); | |
Debug.WriteLine(string.Format("per rep {0}ms", time / reps)); | |
Debug.WriteLine(string.Format("total {0}ms", time)); | |
} | |
[Test] | |
public void Concat() | |
{ | |
var format1 = String.Concat("My ", foo, " likes to eat ", bar); | |
var startNew = Stopwatch.StartNew(); | |
for (var i = 0; i < reps; i++) | |
{ | |
var format = String.Concat("My ",foo," likes to eat ",bar); | |
} | |
startNew.Stop(); | |
var time = ((double)startNew.ElapsedMilliseconds); | |
Debug.WriteLine(string.Format("per rep {0}ms", time /reps)); | |
Debug.WriteLine(string.Format("total {0}ms", time)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment