Skip to content

add OSPlatform.macOS, switch to OrdinalIgnoreCase for OSPlatform comparisons - #39209

Merged
adamsitnik merged 10 commits into
dotnet:masterfrom
adamsitnik:33331_macOS_ignoreCase
Jul 14, 2020
Merged

add OSPlatform.macOS, switch to OrdinalIgnoreCase for OSPlatform comparisons#39209
adamsitnik merged 10 commits into
dotnet:masterfrom
adamsitnik:33331_macOS_ignoreCase

Conversation

@adamsitnik

Copy link
Copy Markdown
Member

I tried to introduce as small overhead as possible.

On Windows, there is basically no difference. On OSX there is no difference for "OSX" (old check), but the "macOS" check takes twice the time because we need two comparisons.

I've added the test cases that were missing in #39005 (ignore case comparison was not enabled then)

Windows

privatereadonlyOSPlatform_notCurrent=OSPlatform.Create("NOPE");privatereadonlyOSPlatform_current=OSPlatform.Windows;[Benchmark]publicboolIsOSPlatform_True()=>RuntimeInformation.IsOSPlatform(_current);[Benchmark]publicboolIsOSPlatform_False()=>RuntimeInformation.IsOSPlatform(_notCurrent);
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.900 (1909/November2018Update/19H2)
Intel Xeon CPU E5-1650 v4 3.60GHz, 1 CPU, 12 logical and 6 physical cores

Before:

MethodMeanErrorStdDevMedianMinMaxGen 0Gen 1Gen 2Allocated
IsOSPlatform_True3.160 ns0.0116 ns0.0103 ns3.158 ns3.145 ns3.183 ns----
IsOSPlatform_False4.592 ns0.0139 ns0.0130 ns4.590 ns4.571 ns4.613 ns----

After:

MethodMeanErrorStdDevMedianMinMaxGen 0Gen 1Gen 2Allocated
IsOSPlatform_True3.177 ns0.0210 ns0.0197 ns3.171 ns3.152 ns3.213 ns----
IsOSPlatform_False4.739 ns0.0126 ns0.0112 ns4.741 ns4.722 ns4.761 ns----

OSX

BenchmarkDotNet=v0.12.1, OS=macOS Mojave 10.14.5 (18F132) [Darwin 18.6.0]
Intel Core i7-5557U CPU 3.10GHz (Broadwell), 1 CPU, 4 logical and 2 physical cores
privatereadonlyOSPlatform_notCurrent=OSPlatform.Create("NOPE");privatereadonlyOSPlatform_current=OSPlatform.OSX;privatereadonlyOSPlatform_macOS=OSPlatform.macOS;[Benchmark]publicboolIsOSPlatform_True()=>RuntimeInformation.IsOSPlatform(_current);[Benchmark]publicboolIsOSPlatform_macOS()=>RuntimeInformation.IsOSPlatform(_macOS);[Benchmark]publicboolIsOSPlatform_False()=>RuntimeInformation.IsOSPlatform(_notCurrent);

Before:

MethodMeanErrorStdDevMedianMinMaxGen 0Gen 1Gen 2Allocated
IsOSPlatform_True2.901 ns0.0071 ns0.0063 ns2.901 ns2.892 ns2.915 ns----
IsOSPlatform_macOS4.091 ns0.0092 ns0.0077 ns4.089 ns4.081 ns4.106 ns----
IsOSPlatform_False4.415 ns0.0209 ns0.0163 ns4.411 ns4.402 ns4.463 ns----

After:

MethodMeanErrorStdDevMedianMinMaxGen 0Gen 1Gen 2Allocated
IsOSPlatform_True2.887 ns0.0057 ns0.0048 ns2.886 ns2.880 ns2.897 ns----
IsOSPlatform_macOS7.972 ns0.0146 ns0.0130 ns7.968 ns7.956 ns7.996 ns----
IsOSPlatform_False9.689 ns0.0378 ns0.0335 ns9.682 ns9.627 ns9.751 ns----

@Dotnet-GitSync-Bot

Copy link
Copy Markdown
Collaborator

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@Dotnet-GitSync-Bot

Copy link
Copy Markdown
Collaborator

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@jeffhandleyjeffhandley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. I'm going to add @jkotas as a reviewer too though; we should wait for his approval before merging.

@jeffhandley
jeffhandley requested a review from jkotasJuly 13, 2020 18:27
adamsitnikand others added 2 commits July 14, 2020 10:02
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Co-authored-by: Jan Kotas <jkotas@microsoft.com>

@jkotasjkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@adamsitnik
adamsitnik merged commit 2c573b5 into dotnet:masterJul 14, 2020
@adamsitnik
adamsitnik deleted the 33331_macOS_ignoreCase branch July 14, 2020 17:06
@jeffhandley

Copy link
Copy Markdown
Member

Thanks, @adamsitnik and @jkotas!

@safernsafern mentioned this pull request Jul 16, 2020
7 tasks
safern added a commit that referenced this pull request Jul 16, 2020
@ghostghost locked as resolved and limited conversation to collaborators Dec 8, 2020
Sign up for freeto 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.

4 participants

@adamsitnik@Dotnet-GitSync-Bot@jeffhandley@jkotas