Skip to content

Instantly share code, notes, and snippets.

@SimonCropp
Created October 24, 2011 09:34
Show Gist options
  • Save SimonCropp/1308672 to your computer and use it in GitHub Desktop.
Save SimonCropp/1308672 to your computer and use it in GitHub Desktop.
string concat tests
[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