public static void SpeedTest()
{
Logger log = new Logger("CharBuffer: SpeedTest");
log.Info("Starting...");
char c = 'a';
string s = null;
int cycles = 1000000;
// a sequence of common ops
StringBuilder sb = new StringBuilder();
DateTime startTime = HighResClock.Now;
for (int i = 0; i < cycles; i++)
{
sb.Append(c);
sb.Append(c);
sb.Append(c);
sb.Append(c);
sb.Append("hello");
s = sb.ToString();
sb.Length = 0;
}
log.Info("StringBuilder paces took: {0} us",
(HighResClock.Now - startTime).TotalMilliseconds * 1000.0 / cycles);
// a sequence of common ops
CharBuffer cb = new CharBuffer(16); // match StringBuilder's default length
startTime = HighResClock.Now;
for (int i = 0; i < cycles; i++)
{
cb.Append(c);
cb.Append(c);
cb.Append(c);
cb.Append(c);
cb.Append("hello");
s = cb.ToString();
cb.Length = 0;
}
log.Info("CharBuffer paces took: {0} us",
(System.DateTime.UtcNow - startTime).TotalMilliseconds * 1000.0 / cycles);
log.Info("Done.");
}