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

FileStream benchmarks #1633

Merged
merged 17 commits into from
Feb 2, 2021
Merged

FileStream benchmarks #1633

merged 17 commits into from
Feb 2, 2021

Conversation

adamsitnik
Copy link
Member

Main changes:

  • add benchmark that copies one file into another (existing benchmark was copying from file to Stream.Null)
  • add Open&Close benchmark
  • add Lock&Unlcok benchmark
  • add Seek (forward and backward) benchmarks
  • give better names to differentiate user buffer (passed to stream) and internal stream buffer (passed by Stream to OS)
  • add more file sizes (1kB, 1MB, 100MB) where it makes sense

cc @stephentoub


[Params(DefaultBufferSize / 8, 200000)]
public int BufferSize;
private const int OneKiloByte = 1_000;
Copy link
Member

@danmoseley danmoseley Jan 19, 2021

Choose a reason for hiding this comment

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

using (FileStream reader = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read, DefaultBufferSize, FileOptions.Asynchronous))
byte[] userBuffer = _userBuffers[userBufferSize];
long bytesRead = 0;
using (FileStream fileStream = new FileStream(_sourceFilePaths[fileSize], FileMode.Open, FileAccess.Read, FileShare.Read, FourKiloBytes, options))
Copy link
Member

Choose a reason for hiding this comment

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

We also end up measuring the open/close time. That's ok?

Copy link
Member Author

Choose a reason for hiding this comment

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

I would like this benchmark to answer the question "How long does it take to read X bytes from a file?". Since opening (and closing) the file is mandatory to read it, I think that it's OK to include it here.

@adamsitnik
Copy link
Member Author

@jozkee @carlossanlop the CI failures are unrelated, PTAL

Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

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

I wonder if we should measure Flush as well?
That aside, looks great to me!

@adamsitnik
Copy link
Member Author

I wonder if we should measure Flush as well?

Great point, I've added benchmark and verified with profiler that most of the time (85%) is spent in Flushing

obraz

@adamsitnik adamsitnik merged commit 358051e into dotnet:master Feb 2, 2021
@adamsitnik adamsitnik deleted the fileStream branch February 2, 2021 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants