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 = 100000;
for( int loop = 0 ; loop < 4 ; loop++ ) {
// +連結
watch = Stopwatch.StartNew();
string[] s = new string[count];
for( int i = 0 ; i < count ; i++ ) {
s[i] = a + b + c + d + e + f + g + h;
}
watch.Stop();
Console.WriteLine( "+:" + watch.ElapsedMilliseconds );
// StringBuilder連結
watch = Stopwatch.StartNew();
StringBuilder bulder = new StringBuilder();
for( int i = 0 ; i < count ; i++ ) {
bulder.Append( a ).Append( b ).Append( c ).Append( d ).Append( e ).Append( f ).Append( g ).Append( h );
// このループでは、文字列を追加するのみ。
}
string ret = bulder.ToString(); // 文字列操作を終えてから文字列(string)を生成する。
watch.Stop();
Console.WriteLine( "StringBuilder:" + watch.ElapsedMilliseconds );
}
Console.ReadLine();
}
[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";
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uRGlhZ25vc3RpY3M7CnVzaW5nIFN5c3RlbS5Db2xsZWN0aW9ucy5HZW5lcmljOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLlRleHQ7Cgpu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