interning

    [C#] String Interning

    C#의 string.Intern 이라는 메서드는 문자열 풀에서 문자열을 풀링시켜 메모리를 아끼고 메모리 비교를 더 빠르게 해준다. 쓰는건 정말 간단하다. a = string.Intern("this is string") 으로 문자열을 넘기면 끝이다. 간단하게 퍼포먼스 비교를 해보자. string a = "dolphin"; string b = "dol"; b += "phin"; bool res = false; var sw = new Stopwatch(); sw.Start(); for (int i = 0; i < 100000000; i++) res = a == b; sw.Stop(); Console.WriteLine("Before intern:"); Console.WriteLine(sw.ElapsedMilli..