static void Check(string s) { const int N = 100; // 計測用に長めの文字列にしたいので 2^10 倍につなぐ for (int i = 0; i < 10; i++) { s = s + s; } var utf8 = Encoding.UTF8.GetBytes(s); #if !ArrayImplementation var utf16 = Encoding.Unicode.GetBytes(s); #else var utf16 = Copy8To16(Encoding.Unicode.GetBytes(s)); #endif GC.Collect(); for (int n = 0; n < 3; n++) { Console.WriteLine("---- " + n + " ----"); using (SW.New("corefxlab code point: ")) { for (int i = 0; i < N; i++) { foreach (var c in new LabUtf8String(utf8)) { ; } } } using (SW.New(" utf-8 code point: ")) { for (int i = 0; i < N; i++) { foreach (var c in new Utf8String(utf8)) { ; } } } using (SW.New(" utf-16 code point: ")) { for (int i = 0; i < N; i++) { foreach (var c in new Utf16String(utf16)) { ; } } } using (SW.New(" utf-8 index : ")) { for (int i = 0; i < N; i++) { var x = new Utf8String(utf8); foreach (var index in x.Indexes) { var c = x[index]; } } } using (SW.New(" utf-16 index : ")) { for (int i = 0; i < N; i++) { var x = new Utf16String(utf16); foreach (var index in x.Indexes) { var c = x[index]; } } } } }