runtime icon indicating copy to clipboard operation
runtime copied to clipboard

Improve IPAddress to/from bytes perf

Open stephentoub opened this issue 3 years ago • 1 comments

Also cleaned up some unnecessary !s with MemberNotNullWhen.

private IPAddress _addr1 = IPAddress.Parse("1.2.3.4").MapToIPv6();
private IPAddress _addr2 = IPAddress.Parse("2600:141b:13:781::356e");
private IPAddress _addr3 = IPAddress.Parse("2600:141b:13:781::356e");
private byte[] _ipv6Bytes = IPAddress.Parse("2600:141b:13:781::356e").GetAddressBytes();

[Benchmark] public bool IsIPv4MappedToIPv6_True() => _addr1.IsIPv4MappedToIPv6;
[Benchmark] public bool IsIPv4MappedToIPv6_False() => _addr2.IsIPv4MappedToIPv6;
[Benchmark] public IPAddress NewIPv6() => new IPAddress(_ipv6Bytes, 0);
[Benchmark] public bool WriteBytes() => _addr3.TryWriteBytes(_ipv6Bytes, out _);
Method Toolchain Mean Ratio
IsIPv4MappedToIPv6_True \main\corerun.exe 2.965 ns 1.00
IsIPv4MappedToIPv6_True \pr\corerun.exe 1.094 ns 0.36
IsIPv4MappedToIPv6_False \main\corerun.exe 1.210 ns 1.00
IsIPv4MappedToIPv6_False \pr\corerun.exe 1.183 ns 0.98
NewIPv6 \main\corerun.exe 21.082 ns 1.00
NewIPv6 \pr\corerun.exe 14.129 ns 0.67
WriteBytes \main\corerun.exe 12.068 ns 1.00
WriteBytes \pr\corerun.exe 2.227 ns 0.18

stephentoub avatar Sep 20 '22 02:09 stephentoub

Tagging subscribers to this area: @dotnet/ncl See info in area-owners.md if you want to be subscribed.

Issue Details

Also cleaned up some unnecessary !s with MemberNotNullWhen.

private IPAddress _addr1 = IPAddress.Parse("1.2.3.4").MapToIPv6();
private IPAddress _addr2 = IPAddress.Parse("2600:141b:13:781::356e");
private IPAddress _addr3 = IPAddress.Parse("2600:141b:13:781::356e");
private byte[] _ipv6Bytes = IPAddress.Parse("2600:141b:13:781::356e").GetAddressBytes();

[Benchmark] public bool IsIPv4MappedToIPv6_True() => _addr1.IsIPv4MappedToIPv6;
[Benchmark] public bool IsIPv4MappedToIPv6_False() => _addr2.IsIPv4MappedToIPv6;
[Benchmark] public IPAddress NewIPv6() => new IPAddress(_ipv6Bytes, 0);
[Benchmark] public bool WriteBytes() => _addr3.TryWriteBytes(_ipv6Bytes, out _);
Method Toolchain Mean Ratio
IsIPv4MappedToIPv6_True \main\corerun.exe 2.965 ns 1.00
IsIPv4MappedToIPv6_True \pr\corerun.exe 1.094 ns 0.36
IsIPv4MappedToIPv6_False \main\corerun.exe 1.210 ns 1.00
IsIPv4MappedToIPv6_False \pr\corerun.exe 1.183 ns 0.98
NewIPv6 \main\corerun.exe 21.082 ns 1.00
NewIPv6 \pr\corerun.exe 14.129 ns 0.67
WriteBytes \main\corerun.exe 12.068 ns 1.00
WriteBytes \pr\corerun.exe 2.227 ns 0.18
Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Net

Milestone: -

ghost avatar Sep 20 '22 02:09 ghost

/azp run runtime-extra-platforms

stephentoub avatar Sep 23 '22 02:09 stephentoub

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Sep 23 '22 02:09 azure-pipelines[bot]

Improvements https://github.com/dotnet/perf-autofiling-issues/issues/8818#issuecomment-1266628997 (and other improvements throughout the issue. We are filing all improvements and regressions from a single commit range in a single issue now, hence why this is so long and contains unrelated regressions)

dakersnar avatar Oct 04 '22 16:10 dakersnar