Files
ssh.net/test/Renci.SshNet.IntegrationBenchmarks/ScpClientBenchmark.cs
T
mus65 c0a353a4de Cleanup formatting and style and enforce it in CI (#1380)
* Preparation to enforce formatting and style in CI

- enabled IDE0055 to enforce formatting on build
- disabled SA1137 and SA1025 because they are already
  covered by IDE0055
- disabled SA1021 because it conflicts with csharp_space_after_cast

* Cleanup formatting and style on codebase

This commit has no manual changes, it is the result
of running "dotnet format whitespace" and "dotnet format style"

* new formatting fixes after merge

* appveyor: set git autocrlf

as suggested by sharwell to hopefully fix Windows CI.

* use autocrlf input

to hopefully fix Linux tests

* fix formatting

* use autocrlf input for Linux only

* set csharp_space_after_cast to false

* Revert SA1021 suppression

---------

Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2024-05-17 22:34:27 +02:00

81 lines
3.0 KiB
C#

using System.Text;
using BenchmarkDotNet.Attributes;
using Renci.SshNet.IntegrationTests.TestsFixtures;
namespace Renci.SshNet.IntegrationBenchmarks
{
[MemoryDiagnoser]
[SimpleJob]
public class ScpClientBenchmark : IntegrationBenchmarkBase
{
private readonly InfrastructureFixture _infrastructureFixture;
private readonly string _file = $"/tmp/{Guid.NewGuid()}.txt";
private ScpClient? _scpClient;
private MemoryStream? _uploadStream;
public ScpClientBenchmark()
{
_infrastructureFixture = InfrastructureFixture.Instance;
}
[GlobalSetup]
public async Task Setup()
{
await GlobalSetup().ConfigureAwait(false);
_scpClient = new ScpClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
await _scpClient.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
var fileContent = "File content !@#$%^&*()_+{}:,./<>[];'\\|";
_uploadStream = new MemoryStream(Encoding.UTF8.GetBytes(fileContent));
}
[GlobalCleanup]
public async Task Cleanup()
{
await GlobalCleanup().ConfigureAwait(false);
await _uploadStream!.DisposeAsync().ConfigureAwait(false);
}
[Benchmark]
public void Connect()
{
using var scpClient = new ScpClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
scpClient.Connect();
}
[Benchmark]
public async Task ConnectAsync()
{
using var scpClient = new ScpClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
await scpClient.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
}
[Benchmark]
public string ConnectUploadAndDownload()
{
using var scpClient = new ScpClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
scpClient.Connect();
_uploadStream!.Position = 0;
scpClient.Upload(_uploadStream, _file);
using var downloadStream = new MemoryStream();
scpClient.Download(_file, downloadStream);
return Encoding.UTF8.GetString(downloadStream.ToArray());
}
[Benchmark]
public string UploadAndDownload()
{
_uploadStream!.Position = 0;
_scpClient!.Upload(_uploadStream, _file);
using var downloadStream = new MemoryStream();
_scpClient.Download(_file, downloadStream);
return Encoding.UTF8.GetString(downloadStream.ToArray());
}
}
}