/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Servers/Kestrel/perf/Microbenchmarks/IntegerDecoderBenchmark.cs
41 строка
1 KB
Pranav K
Use file scoped namespaces (#38076)
06 ноя 2021, 03:52
Не верифицирован
06 ноя 2021, 03:52
a450cb6
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Net.Http.HPack; using BenchmarkDotNet.Attributes; namespace Microsoft.AspNetCore.Server.Kestrel.Microbenchmarks; public class IntegerDecoderBenchmark { private const int Iterations = 50_000; private readonly int _prefixLength = 5; // Arbitrary prefix length private readonly byte _singleByte = 0x1e; // 30 private readonly byte[] _multiByte = new byte[] { 0x1f, 0xe0, 0xff, 0xff, 0xff, 0x03 }; // int32.MaxValue [Benchmark(Baseline = true, OperationsPerInvoke = Iterations)] public void DecodeSingleByteInteger() { var integerDecoder = new IntegerDecoder(); for (var i = 0; i < Iterations; i++) { integerDecoder.BeginTryDecode(_singleByte, _prefixLength, out _); } } [Benchmark(OperationsPerInvoke = Iterations)] public void DecodeMultiByteInteger() { var integerDecoder = new IntegerDecoder(); for (var i = 0; i < Iterations; i++) { integerDecoder.BeginTryDecode(_multiByte[0], _prefixLength, out _); for (var j = 1; j < _multiByte.Length; j++) { integerDecoder.TryDecode(_multiByte[j], out _); } } } }