using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch watch;
string a, b, c, d, e, f, g, h;
SetString(out a, out b, out c, out d, out e, out f, out g, out h);
int count = 1000000;
string[] s = new string[count];
for (int loop = 0; loop < 8; loop++)
{
GC.Collect();
watch = Stopwatch.StartNew();
for (int i = 0; i < count; i++)
{
s[i] = a + b + c + d;
}
watch.Stop();
Console.WriteLine("+:" + watch.ElapsedMilliseconds);
GC.Collect();
watch = Stopwatch.StartNew();
StringBuilder bulder = new StringBuilder();
for (int i = 0; i < count; i++)
{
bulder.Append(a).Append(b).Append(c).Append(d);
s[i] = bulder.ToString();
bulder.Clear();
}
watch.Stop();
Console.WriteLine("StringBuilder:" + watch.ElapsedMilliseconds);
}
}
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
static void SetString(out string a, out string b, out string c, out string d, out string e, out string f, out string g, out string h)
{
a = "AAAAAAAAAAAAAAAAA";
b = "BBBBBBBBBBBBBBBBBBBBBBBB";
c = "CCCCCCCCCCCCCCCCCCCC";
d = "DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD";
e = "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE";
f = "FFFFFFFFFFFFFFFFFFFFFF";
g = "GGGGGGGGGGGGGGGGG";
h = "HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH";
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uRGlhZ25vc3RpY3M7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLlRleHQ7CgpuYW1lc3BhY2UgQ29uc29sZUFwcGxpY2F0aW9uMQp7CiAgICBjbGFzcyBQcm9ncmFtCiAgICB7CiAgICAgICAgc3RhdGljIHZvaWQgTWFpbihzdHJpbmdbXSBhcmdzKQogICAgICAgIHsKICAgICAgICAgICAgU3RvcHdhdGNoIHdhdGNoOwoKICAgICAgICAgICAgc3RyaW5nIGEsIGIsIGMsIGQsIGUsIGYsIGcsIGg7CiAgICAgICAgICAgIFNldFN0cmluZyhvdXQgYSwgb3V0ICBiLCBvdXQgIGMsIG91dCBkLCBvdXQgZSwgb3V0IGYsIG91dCBnLCBvdXQgaCk7CgogICAgICAgICAgICBpbnQgY291bnQgPSAxMDAwMDAwOwogICAgICAgICAgICBzdHJpbmdbXSBzID0gbmV3IHN0cmluZ1tjb3VudF07CgogICAgICAgICAgICBmb3IgKGludCBsb29wID0gMDsgbG9vcCA8IDg7IGxvb3ArKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgR0MuQ29sbGVjdCgpOwogICAgICAgICAgICAgICAgd2F0Y2ggPSBTdG9wd2F0Y2guU3RhcnROZXcoKTsKICAgICAgICAgICAgICAgIGZvciAoaW50IGkgPSAwOyBpIDwgY291bnQ7IGkrKykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBzW2ldID0gYSArIGIgKyBjICsgZDsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIHdhdGNoLlN0b3AoKTsKICAgICAgICAgICAgICAgIENvbnNvbGUuV3JpdGVMaW5lKCIrOiIgKyB3YXRjaC5FbGFwc2VkTWlsbGlzZWNvbmRzKTsKCiAgICAgICAgICAgICAgICBHQy5Db2xsZWN0KCk7CiAgICAgICAgICAgICAgICB3YXRjaCA9IFN0b3B3YXRjaC5TdGFydE5ldygpOwogICAgICAgICAgICAgICAgU3RyaW5nQnVpbGRlciBidWxkZXIgPSBuZXcgU3RyaW5nQnVpbGRlcigpOwogICAgICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBjb3VudDsgaSsrKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIGJ1bGRlci5BcHBlbmQoYSkuQXBwZW5kKGIpLkFwcGVuZChjKS5BcHBlbmQoZCk7CiAgICAgICAgICAgICAgICAgICAgc1tpXSA9IGJ1bGRlci5Ub1N0cmluZygpOwogICAgICAgICAgICAgICAgICAgIGJ1bGRlci5DbGVhcigpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgd2F0Y2guU3RvcCgpOwogICAgICAgICAgICAgICAgQ29uc29sZS5Xcml0ZUxpbmUoIlN0cmluZ0J1aWxkZXI6IiArIHdhdGNoLkVsYXBzZWRNaWxsaXNlY29uZHMpOwogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBbU3lzdGVtLlJ1bnRpbWUuQ29tcGlsZXJTZXJ2aWNlcy5NZXRob2RJbXBsKFN5c3RlbS5SdW50aW1lLkNvbXBpbGVyU2VydmljZXMuTWV0aG9kSW1wbE9wdGlvbnMuTm9JbmxpbmluZyldCiAgICAgICAgc3RhdGljIHZvaWQgU2V0U3RyaW5nKG91dCBzdHJpbmcgYSwgb3V0IHN0cmluZyBiLCBvdXQgc3RyaW5nIGMsIG91dCBzdHJpbmcgZCwgb3V0IHN0cmluZyBlLCBvdXQgc3RyaW5nIGYsIG91dCBzdHJpbmcgZywgb3V0IHN0cmluZyBoKQogICAgICAgIHsKICAgICAgICAgICAgYSA9ICJBQUFBQUFBQUFBQUFBQUFBQSI7CiAgICAgICAgICAgIGIgPSAiQkJCQkJCQkJCQkJCQkJCQkJCQkJCQkJCIjsKICAgICAgICAgICAgYyA9ICJDQ0NDQ0NDQ0NDQ0NDQ0NDQ0NDQyI7CiAgICAgICAgICAgIGQgPSAiREREREREREREREREREREREREREREREREREREREREREREREREREREREREIjsKICAgICAgICAgICAgZSA9ICJFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUVFRUUiOwogICAgICAgICAgICBmID0gIkZGRkZGRkZGRkZGRkZGRkZGRkZGRkYiOwogICAgICAgICAgICBnID0gIkdHR0dHR0dHR0dHR0dHR0dHIjsKICAgICAgICAgICAgaCA9ICJISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIIjsKICAgICAgICB9CgogICAgfQp9Cg==