Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Benchmarque Blog Post Code

View AppendText.cs
1 2 3 4
public interface AppendText
{
string Append(params string[] args);
}
View AppendText.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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;
}
}
View AppendText.cs
1 2 3 4 5 6 7 8
public class JoinAppendText :
AppendText
{
public string Append(params string[] args)
{
return string.Join("", args);
}
}
View AppendText.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
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}; }
}
}
View AppendText.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14
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
Something went wrong with that request. Please try again.