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

Add benchmark for File.Move #2437

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

deeprobin
Copy link

This PR is used to introduce a benchmark to measure the performance of File.Move.
See dotnet/runtime#65092

/cc @adamsitnik

@carlossanlop
Copy link
Member

@adamsitnik should we consider categorizing System.IO benchmarks by the filesystem they are running against? The results might differ a lot if the drive is NTFS, EXT4, EXFAT, etc., even within the same OS and .NET version.

{
if (File.Exists(_moveDestination))
{
File.Delete(_moveDestination);
Copy link
Member

Choose a reason for hiding this comment

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

I believe File.Delete does not need protecting with File.Exists

Copy link
Author

Choose a reason for hiding this comment

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

I have taken the procedure from other methods in the class.

private string _moveSource;
private string _moveDestination;

[IterationSetup(Target = nameof(Move))]
Copy link
Member

Choose a reason for hiding this comment

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

we try not to use IterationSetup if possible: https://github.com/dotnet/performance/blob/main/docs/microbenchmark-design-guidelines.md#iterationsetup

In case of move benchmark, we could just swap the files:

private ulong counter;

[Benchmark]
public void Move()
{
     if (counter++ % 2 == 0)
         File.Move(_moveSource, _moveDestination);
     else
         File.Move(_moveDestination, _moveSource);
}

@danmoseley
Copy link
Member

@deeprobin do you plan to address feedback?

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

Successfully merging this pull request may close these issues.

4 participants