| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using BenchmarkDotNet.Attributes;
- using Renci.SshNet.IntegrationTests.TestsFixtures;
- namespace Renci.SshNet.IntegrationBenchmarks
- {
- [MemoryDiagnoser]
- [SimpleJob]
- public class SshClientBenchmark : IntegrationBenchmarkBase
- {
- private readonly InfrastructureFixture _infrastructureFixture;
- private SshClient? _sshClient;
- public SshClientBenchmark()
- {
- _infrastructureFixture = InfrastructureFixture.Instance;
- }
- [GlobalSetup]
- public async Task Setup()
- {
- await GlobalSetup().ConfigureAwait(false);
- _sshClient = new SshClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
- await _sshClient.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
- }
- [GlobalCleanup]
- public async Task Cleanup()
- {
- await GlobalCleanup().ConfigureAwait(false);
- }
- [Benchmark]
- public void Connect()
- {
- using var sshClient = new SshClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
- sshClient.Connect();
- }
- [Benchmark]
- public async Task ConnectAsync()
- {
- using var sshClient = new SshClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
- await sshClient.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
- }
- [Benchmark]
- public string ConnectAndRunCommand()
- {
- using var sshClient = new SshClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
- sshClient.Connect();
- return sshClient.RunCommand("echo $'test !@#$%^&*()_+{}:,./<>[];\\|'").Result;
- }
- [Benchmark]
- public async Task<string> ConnectAsyncAndRunCommand()
- {
- using var sshClient = new SshClient(_infrastructureFixture.SshServerHostName, _infrastructureFixture.SshServerPort, _infrastructureFixture.User.UserName, _infrastructureFixture.User.Password);
- await sshClient.ConnectAsync(CancellationToken.None).ConfigureAwait(false);
- return sshClient.RunCommand("echo $'test !@#$%^&*()_+{}:,./<>[];\\|'").Result;
- }
- [Benchmark]
- public string RunCommand()
- {
- return _sshClient!.RunCommand("echo $'test !@#$%^&*()_+{}:,./<>[];\\|'").Result;
- }
- }
- }
|