private unsafe static void InternalParserByteSpanToUInt32_VariableLength()
        {
            List <ReadOnlySpan <byte> > byteSpanList = new List <ReadOnlySpan <byte> >();

            foreach (string text in s_UInt32TextArray)
            {
                byte[] utf8ByteArray             = Encoding.UTF8.GetBytes(text);
                ReadOnlySpan <byte> utf8ByteSpan = new ReadOnlySpan <byte>(utf8ByteArray);
                byteSpanList.Add(utf8ByteSpan);
            }
            EncodingData fd = EncodingData.InvariantUtf8;
            TextFormat   nf = new TextFormat('N');

            foreach (var iteration in Benchmark.Iterations)
            {
                int bytesConsumed;
                using (iteration.StartMeasurement())
                {
                    for (int i = 0; i < LoadIterations; i++)
                    {
                        ReadOnlySpan <byte> utf8ByteSpan = byteSpanList[i % 10];
                        uint value;
                        InternalParser.TryParseUInt32(utf8ByteSpan, fd, nf, out value, out bytesConsumed);
                        DoNotIgnore(value, bytesConsumed);
                    }
                }
            }
        }
        [InlineData("0")]          // min value
        private unsafe static void InternalParserByteStarToUInt32(string text)
        {
            int length = text.Length;

            byte[]       utf8ByteArray = Encoding.UTF8.GetBytes(text);
            EncodingData fd            = EncodingData.InvariantUtf8;
            TextFormat   nf            = new TextFormat('N');

            foreach (var iteration in Benchmark.Iterations)
            {
                int bytesConsumed;
                fixed(byte *utf8ByteStar = utf8ByteArray)
                {
                    using (iteration.StartMeasurement())
                    {
                        for (int i = 0; i < LoadIterations; i++)
                        {
                            uint value;
                            InternalParser.TryParseUInt32(utf8ByteStar, 0, length, fd, nf, out value, out bytesConsumed);
                            DoNotIgnore(value, bytesConsumed);
                        }
                    }
                }
            }
        }
Пример #3
0
        public unsafe void ParseSubstringToUInt32(string text, int index, int count, uint expectedValue, int expectedConsumed)
        {
            uint parsedValue;
            int  charsConsumed;
            bool result = InternalParser.TryParseUInt32(text, index, count, out parsedValue, out charsConsumed);

            Assert.True(result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedConsumed, charsConsumed);
        }
Пример #4
0
        public unsafe void ParseSpanOfCharToUInt32(string text, uint expectedValue, int expectedConsumed)
        {
            var  span = new ReadOnlySpan <char>(text.ToCharArray());
            uint parsedValue;
            int  charsConsumed;
            bool result = InternalParser.TryParseUInt32(span, out parsedValue, out charsConsumed);

            Assert.True(result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedConsumed, charsConsumed);
        }
Пример #5
0
        public unsafe void ParseUtf8StringToUInt32(string text, uint expectedValue, int expectedConsumed)
        {
            var utf8 = new Utf8String(text);

            uint parsedValue;
            int  bytesConsumed;
            bool result = InternalParser.TryParseUInt32(utf8, out parsedValue, out bytesConsumed);

            Assert.True(result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedConsumed, bytesConsumed);
        }
Пример #6
0
        public unsafe void ParseUtf8SpanOfBytesToUInt32(string text, uint expectedValue, int expectedConsumed)
        {
            byte[] textBuffer = Encoding.UTF8.GetBytes(text);
            var    span       = new ReadOnlySpan <byte>(textBuffer);

            uint parsedValue;
            int  bytesConsumed;
            bool result = InternalParser.TryParseUInt32(span, TextEncoding.Utf8, out parsedValue, out bytesConsumed);

            Assert.True(result);
            Assert.Equal(expectedValue, parsedValue);
            Assert.Equal(expectedConsumed, bytesConsumed);
        }