Created
July 18, 2012 15:54
-
-
Save phatboyg/3137095 to your computer and use it in GitHub Desktop.
Benchmarque Blog Post Code
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
public interface AppendText | |
{ | |
string Append(params string[] args); | |
} |
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
public class ConcatAppendText : | |
AppendText | |
{ | |
public string Append(params string[] args) | |
{ | |
string result = string.Empty; | |
for (int i = 0; i < args.Length; i++) | |
{ | |
result += args[i]; | |
} | |
return result; | |
} | |
} |
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
public class JoinAppendText : | |
AppendText | |
{ | |
public string Append(params string[] args) | |
{ | |
return string.Join("", args); | |
} | |
} |
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
public class NameAppendBenchmark : | |
Benchmark<AppendText> | |
{ | |
static readonly string[] Names = new[] | |
{ | |
"Adam", "Betty", "Charles", "David", | |
"Edward", "Frodo", "Gandalf", "Henry", | |
"Ida", "John", "King", "Larry", "Morpheus", | |
"Neo", "Peter", "Quinn", "Ralphie", "Samwise", | |
"Trinity", "Umma", "Vincent", "Wanda" | |
}; | |
public void WarmUp(AppendText instance) | |
{ | |
instance.Append(Names); | |
} | |
public void Shutdown(AppendText instance) | |
{ | |
} | |
public void Run(AppendText instance, int iterationCount) | |
{ | |
for (int i = 0; i < iterationCount; i++) | |
{ | |
string result = instance.Append(Names); | |
} | |
} | |
public IEnumerable<int> Iterations | |
{ | |
get { return new[] {1000, 10000}; } | |
} | |
} |
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
public class StringBuilderAppendText : | |
AppendText | |
{ | |
public string Append(params string[] args) | |
{ | |
var builder = new StringBuilder(); | |
for (int i = 0; i < args.Length; i++) | |
{ | |
builder.Append(args[i]); | |
} | |
return builder.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment