示例#1
0
        public unsafe void ReverseEnumerateCodePointsConstructFromSpan()
        {
            TestCase[] testCases = new TestCase[] {
                new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 3000000),
                new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 3000000),
                new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 300),
                new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 300)
            };
            foreach (TestCase testData in testCases)
            {
                string     s     = testData.String;
                Utf8String utf8s = new Utf8String(s);
                fixed(byte *bytes = utf8s.CopyBytes())
                {
                    utf8s = new Utf8String(new Span <byte>(bytes, utf8s.Length));
                    int iterations = testData.Iterations;

                    _timer.Restart();
                    while (iterations-- != 0)
                    {
                        Utf8String.CodePointReverseEnumerator it = utf8s.CodePoints.GetReverseEnumerator();
                        while (it.MoveNext())
                        {
                            var codePoint = it.Current;
                        }
                    }
                    PrintTime(testData);
                }
            }
        }
示例#2
0
 public void ReverseEnumerateCodePointsConstructFromByteArray()
 {
     TestCase[] testCases = new TestCase[] {
         new TestCase(GetRandomString(5, 32, 126), "Short ASCII string", 3000000),
         new TestCase(GetRandomString(5, 32, 0xD7FF), "Short string", 3000000),
         new TestCase(GetRandomString(50000, 32, 126), "Long ASCII string", 300),
         new TestCase(GetRandomString(50000, 32, 0xD7FF), "Long string", 300)
     };
     foreach (TestCase testData in testCases)
     {
         string     s     = testData.String;
         Utf8String utf8s = new Utf8String(s);
         utf8s = new Utf8String(utf8s.CopyBytes());
         int iterations = testData.Iterations;
         _timer.Restart();
         while (iterations-- != 0)
         {
             Utf8String.CodePointReverseEnumerator it = utf8s.CodePoints.GetReverseEnumerator();
             while (it.MoveNext())
             {
                 UnicodeCodePoint codePoint = it.Current;
             }
         }
         PrintTime(testData);
     }
 }
示例#3
0
        public unsafe void ReverseEnumerateCodePointsConstructFromSpan(int length, int minCodePoint, int maxCodePoint, string description, bool useInnerLoop = false)
        {
            string     s     = GetRandomString(length, minCodePoint, maxCodePoint);
            Utf8String utf8s = new Utf8String(s);

            fixed(byte *bytes = utf8s.CopyBytes())
            {
                utf8s = new Utf8String(new Span <byte>(bytes, utf8s.Length));

                foreach (var iteration in Benchmark.Iterations)
                {
                    using (iteration.StartMeasurement())
                    {
                        for (int i = 0; i < (useInnerLoop ? Benchmark.InnerIterationCount : 1); i++)
                        {
                            Utf8String.CodePointReverseEnumerator it = utf8s.CodePoints.GetReverseEnumerator();
                            while (it.MoveNext())
                            {
                                var codePoint = it.Current;
                            }
                        }
                    }
                }
            }
        }
示例#4
0
        private void TestCodePointReverseEnumerator(string s, Utf8String u8s)
        {
            List<UnicodeCodePoint> codePoints = new List<UnicodeCodePoint>();
            Utf8String.CodePointReverseEnumerator it = u8s.CodePoints.GetReverseEnumerator();
            while (it.MoveNext())
            {
                codePoints.Add(it.Current);
            }

            codePoints.Reverse();

            Utf16LittleEndianCodePointEnumerable utf16CodePoints = new Utf16LittleEndianCodePointEnumerable(s);
            Assert.Equal(utf16CodePoints, codePoints);

            Utf8String u8s2 = new Utf8String(codePoints);
            Assert.Equal(u8s, u8s2);
            Assert.Equal(s, u8s2.ToString());
        }