소스
string src = "abcd"; string dest = "ABCD"; int maxIter = 10000; int matchCount = 0;
Stopwatch sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (src.ToLower() == dest.ToLower()) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("Lower Equal " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (src.ToUpper() == dest.ToUpper()) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("Upper Equal " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (src.Equals(dest, StringComparison.InvariantCultureIgnoreCase)) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("StringComparison.Ordinal InvariantCultureIgnoreCase " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (src.Equals(dest, StringComparison.CurrentCultureIgnoreCase)) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("StringComparison.Ordinal CurrentCultureIgnoreCase " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (src.Equals(dest, StringComparison.OrdinalIgnoreCase)) matchCount++; }
sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("StringComparison.Ordinal OrdinalIgnoreCase " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (string.Compare(src, dest, true) == 0) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("string.Compare Ignore " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (string.CompareOrdinal(src.ToLower(), dest.ToLower()) == 0) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("string.CompareOrdinal ToLower " + sw.Elapsed.ToString());
sw = Stopwatch.StartNew(); matchCount = 0; for (int i = 0; i < maxIter; i++) { if (string.CompareOrdinal(src.ToUpper(), dest.ToUpper()) == 0) matchCount++; } sw.Stop(); if (matchCount != maxIter) return; Console.WriteLine("string.CompareOrdinal ToUpper " + sw.Elapsed.ToString());
|
결과
string.CompareOrdinal ToUpper 00:00:00.0020907 |
'.Net > C#' 카테고리의 다른 글
C# 원문자 구하기 (0) | 2015.10.05 |
---|---|
SerialPort Read Blocking 시키기 (0) | 2015.08.05 |
C# Excel Sheet의 작성한 전체 데이터 가져오기 (0) | 2014.12.18 |
C# Excel 2013 추가 기능 - 컨트롤 아이디 확인 (0) | 2014.10.13 |
C# Excel 2013 추가 기능 - Ribbon Tab 위치 변경 (0) | 2014.09.30 |