Skip to content

@phatboyg /AppendText.cs
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Benchmarque Blog Post Code
public interface AppendText
{
string Append(params string[] args);
}
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;
}
}
public class JoinAppendText :
AppendText
{
public string Append(params string[] args)
{
return string.Join("", args);
}
}
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}; }
}
}
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.