RTools.Util.CharBuffer.ToString C# (CSharp) Method

ToString() public method

Return the current contents as a string.
public ToString ( ) : String
return String
        public override String ToString()
        {
            return (new String(buffer, headIndex, tailIndex - headIndex));
        }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Compare speed to StringBuilder.
        /// </summary>
        public static void SpeedTest()
        {
            Logger log = new Logger("CharBuffer: SpeedTest");

            log.Info("Starting...");

            char   c      = 'a';
            string s      = null;
            int    cycles = 1000000;

            // a sequence of common ops
            StringBuilder sb        = new StringBuilder();
            DateTime      startTime = HighResClock.Now;

            for (int i = 0; i < cycles; i++)
            {
                sb.Append(c);
                sb.Append(c);
                sb.Append(c);
                sb.Append(c);
                sb.Append("hello");
                s         = sb.ToString();
                sb.Length = 0;
            }
            log.Info("StringBuilder paces took: {0} us",
                     (HighResClock.Now - startTime).TotalMilliseconds * 1000.0 / cycles);

            // a sequence of common ops
            CharBuffer cb = new CharBuffer(16);             // match StringBuilder's default length

            startTime = HighResClock.Now;
            for (int i = 0; i < cycles; i++)
            {
                cb.Append(c);
                cb.Append(c);
                cb.Append(c);
                cb.Append(c);
                cb.Append("hello");
                s         = cb.ToString();
                cb.Length = 0;
            }
            log.Info("CharBuffer paces took: {0} us",
                     (HighResClock.Now - startTime).TotalMilliseconds * 1000.0 / cycles);

            log.Info("Done.");
        }
All Usage Examples Of RTools.Util.CharBuffer::ToString