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

Append() public method

Append a string to this buffer.
public Append ( CharBuffer s ) : void
s CharBuffer The string to append.
return void
        public void Append(CharBuffer s)
        {
            if (s.Length + tailIndex >= capacity) CheckCapacity(Length + s.Length);
            for (int i = 0; i < s.Length; i++)
                buffer[tailIndex++] = s[i];
        }

Same methods

CharBuffer::Append ( char c ) : void
CharBuffer::Append ( string s ) : void

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::Append