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

Use LastIndexOf{Any} in Path.GetFileName #75318

Merged
merged 2 commits into from
Sep 10, 2022

Conversation

stephentoub
Copy link
Member

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.IO;

[HideColumns("Error", "StdDev", "Median", "RatioSD")]
public partial class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

    [Benchmark]
    [Arguments(@"C:\test.txt")]
    [Arguments(@"C:\Users\stoub\Desktop\Benchmarks\Program.cs")]
    [Arguments(@"D:\repos\runtime\src\libraries\System.Private.CoreLib\src\System\IO\MemoryStream.cs")]
    public ReadOnlySpan<char> GetFileName(string path) => Path.GetFileName(path.AsSpan());
}
Method Job Toolchain path Mean Ratio
GetFileName Job-ZOQARC \main\corerun.exe C:\Us(...)am.cs [44] 16.41 ns 1.00
GetFileName Job-UTQVEC \pr\corerun.exe C:\Us(...)am.cs [44] 12.22 ns 0.74
GetFileName Job-ZOQARC \main\corerun.exe C:\test.txt 14.39 ns 1.00
GetFileName Job-UTQVEC \pr\corerun.exe C:\test.txt 12.00 ns 0.83
GetFileName Job-ZOQARC \main\corerun.exe D:\re(...)am.cs [83] 20.40 ns 1.00
GetFileName Job-UTQVEC \pr\corerun.exe D:\re(...)am.cs [83] 12.27 ns 0.60

@stephentoub stephentoub added area-System.IO tenet-performance Performance related issue labels Sep 9, 2022
@stephentoub stephentoub added this to the 8.0.0 milestone Sep 9, 2022
@ghost ghost assigned stephentoub Sep 9, 2022
@ghost
Copy link

ghost commented Sep 9, 2022

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

Issue Details
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System;
using System.IO;

[HideColumns("Error", "StdDev", "Median", "RatioSD")]
public partial class Program
{
    static void Main(string[] args) => BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);

    [Benchmark]
    [Arguments(@"C:\test.txt")]
    [Arguments(@"C:\Users\stoub\Desktop\Benchmarks\Program.cs")]
    [Arguments(@"D:\repos\runtime\src\libraries\System.Private.CoreLib\src\System\IO\MemoryStream.cs")]
    public ReadOnlySpan<char> GetFileName(string path) => Path.GetFileName(path.AsSpan());
}
Method Job Toolchain path Mean Ratio
GetFileName Job-ZOQARC \main\corerun.exe C:\Us(...)am.cs [44] 16.41 ns 1.00
GetFileName Job-UTQVEC \pr\corerun.exe C:\Us(...)am.cs [44] 12.22 ns 0.74
GetFileName Job-ZOQARC \main\corerun.exe C:\test.txt 14.39 ns 1.00
GetFileName Job-UTQVEC \pr\corerun.exe C:\test.txt 12.00 ns 0.83
GetFileName Job-ZOQARC \main\corerun.exe D:\re(...)am.cs [83] 20.40 ns 1.00
GetFileName Job-UTQVEC \pr\corerun.exe D:\re(...)am.cs [83] 12.27 ns 0.60
Author: stephentoub
Assignees: -
Labels:

area-System.IO, tenet-performance

Milestone: 8.0.0

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you @stephentoub !

@stephentoub
Copy link
Member Author

Failure is #75391

@stephentoub stephentoub merged commit b8c5de2 into dotnet:main Sep 10, 2022
@stephentoub stephentoub deleted the getfilename branch September 10, 2022 15:01
@ghost ghost locked as resolved and limited conversation to collaborators Oct 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO tenet-performance Performance related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants