Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve IPAddress to/from bytes perf #75872

Merged
merged 6 commits into from
Sep 27, 2022
Merged

Conversation

stephentoub
Copy link
Member

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

Also cleaned up some unnecessary `!`s with `MemberNotNullWhen`.
@ghost
Copy link

ghost commented Sep 20, 2022

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: -

@stephentoub
Copy link
Member Author

/azp run runtime-extra-platforms

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@dakersnar
Copy link
Contributor

dakersnar commented Oct 4, 2022

Improvements dotnet/perf-autofiling-issues#8818 (comment) (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)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants