本文整理汇总了C#中System.Runtime.InteropServices.StringBuffer.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# StringBuffer.Clear方法的具体用法?C# StringBuffer.Clear怎么用?C# StringBuffer.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.StringBuffer
的用法示例。
在下文中一共展示了StringBuffer.Clear方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PerfTest
static void PerfTest()
{
var formatter = new StringBuffer();
var builder = new StringBuilder();
GC.Collect(2, GCCollectionMode.Forced, true);
var gcCount = GC.CollectionCount(0);
var timer = Stopwatch.StartNew();
for (int k = 0; k < mul; k++) {
for (int i = 0; i < count; i++)
formatter.AppendFormat(formatTest, v1, v2);
formatter.Clear();
}
timer.Stop();
Console.WriteLine("Mine : {0} us/format", timer.ElapsedMilliseconds * 1000.0 / (count * mul));
Console.WriteLine("GCs : {0}", GC.CollectionCount(0) - gcCount);
Console.WriteLine();
GC.Collect(2, GCCollectionMode.Forced, true);
gcCount = GC.CollectionCount(0);
timer = Stopwatch.StartNew();
for (int k = 0; k < mul; k++) {
for (int i = 0; i < count; i++)
builder.AppendFormat(formatTest, v1, v2);
builder.Clear();
}
timer.Stop();
Console.WriteLine("BCL : {0} us/format", timer.ElapsedMilliseconds * 1000.0 / (count * mul));
Console.WriteLine("GCs : {0}", GC.CollectionCount(0) - gcCount);
}
示例2: Main
static void Main(string[] args)
{
var f = new StringBuffer();
f.AppendFormat(formatTest, v1, v2);
Console.WriteLine(f.ToString());
Console.WriteLine(formatTest, v1, v2);
// test custom formatters
StringBuffer.SetCustomFormatter<Blah>(CustomFormat);
f.Clear();
f.AppendFormat("Hello {0:yes}{0:no}", new Blah { Thing = 42 });
Console.WriteLine(f.ToString());
// test static convenience method
Console.WriteLine(StringBuffer.Format(formatTest, v1, v2));
PerfTest();
#if DEBUG
Console.ReadLine();
#endif
}