Ejemplo n.º 1
0
        public void SpanIndexOfAnyCharAsBytes_Two(int size)
        {
            Span <char> charSpan = new char[size];

            charSpan[size / 2] = '5';
            Span <byte> byteSpan = charSpan.AsBytes();

            int index = 0;

            foreach (BenchmarkIteration iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    for (int i = 0; i < Benchmark.InnerIterationCount; i++)
                    {
                        index |= byteSpan.IndexOfAny <byte>(53, 54);        // '5' = 53
                    }
                }
            }
            Assert.Equal(size > 1 ? size : 0, index);
        }
Ejemplo n.º 2
0
        public void SpanIndexOfAnyCharAsBytes_ContainsLastSearchValue_Many(int size)
        {
            Span <char> charSpan = new char[size];

            charSpan[size / 2] = '5';
            Span <byte>         byteSpan = charSpan.AsBytes();
            ReadOnlySpan <byte> values   = new ReadOnlySpan <byte>(new byte[] { 54, 55, 56, 53 });    // '5' = 53

            int index = 0;

            foreach (BenchmarkIteration iteration in Benchmark.Iterations)
            {
                using (iteration.StartMeasurement())
                {
                    for (int i = 0; i < Benchmark.InnerIterationCount; i++)
                    {
                        index |= byteSpan.IndexOfAny(values);
                    }
                }
            }
            Assert.Equal(size > 1 ? size : 0, index);
        }