Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FormPipeReaderInternalsBenchmark.cs « Microbenchmarks « perf « WebUtilities « Http « src - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8b3c20c2c0979321cac3c2f22180646aff152f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Buffers;
using System.Text;
using BenchmarkDotNet.Attributes;

namespace Microsoft.AspNetCore.WebUtilities.Microbenchmarks
{
    /// <summary>
    /// Test internal parsing speed of FormPipeReader without pipe
    /// </summary>
    public class FormPipeReaderInternalsBenchmark
    {
        private readonly byte[] _singleUtf8 = Encoding.UTF8.GetBytes("foo=bar&baz=boo&haha=hehe&lol=temp");
        private readonly byte[] _firstUtf8 = Encoding.UTF8.GetBytes("foo=bar&baz=bo");
        private readonly byte[] _secondUtf8 = Encoding.UTF8.GetBytes("o&haha=hehe&lol=temp");
        private FormPipeReader _formPipeReader;

        [IterationSetup]
        public void Setup()
        {
            _formPipeReader = new FormPipeReader(null);
        }

        [Benchmark]
        public void ReadUtf8Data()
        {
            var buffer = new ReadOnlySequence<byte>(_singleUtf8);
            KeyValueAccumulator accum = default;

            _formPipeReader.ParseFormValues(ref buffer, ref accum, isFinalBlock: true);
        }

        [Benchmark]
        public void ReadUtf8MultipleBlockData()
        {
            var buffer = ReadOnlySequenceFactory.CreateSegments(_firstUtf8, _secondUtf8);
            KeyValueAccumulator accum = default;

            _formPipeReader.ParseFormValues(ref buffer, ref accum, isFinalBlock: true);
        }
    }
}