Files
speckle-sharp-sdk/tests/Speckle.Sdk.Tests.Performance/Benchmarks/GeneralSendTest.cs
T
Adam Hathcock b343d9bd0d add Id and Json types (#165)
* Can debug dependencies

* Different exceptions

* Uses root id only after we found it to signal the end

* DataChunks are created later and need to be accounted for

* format

* use app ids in tests and references

* check sqlite cache after serialize

* use dummy to go through channels to end

* fmt

* Extend channel lib to batch by size

* fmt

* build fix

* adjust limits

* FIx sending

* Optimize reference generation

* more

* remove tolist

* rework closures to be constant and serializer only deals with current....references bases are cached

* fix chunk creation

* another bug fix

* clean up with factories

* add deserializer factory

* Needed to reference interface

* add Id and Json types

* Fix tests

* remove optional

* add another missing id write

* fix merge

* Fix new code
2024-11-20 09:51:10 +00:00

85 lines
2.8 KiB
C#

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using Microsoft.Extensions.DependencyInjection;
using Speckle.Objects.Geometry;
using Speckle.Sdk.Api;
using Speckle.Sdk.Api.GraphQL.Enums;
using Speckle.Sdk.Api.GraphQL.Models;
using Speckle.Sdk.Common;
using Speckle.Sdk.Credentials;
using Speckle.Sdk.Host;
using Speckle.Sdk.Models;
using Speckle.Sdk.Serialisation;
using Speckle.Sdk.Transports;
namespace Speckle.Sdk.Tests.Performance.Benchmarks;
/// <summary>
/// How many threads on our Deserializer is optimal
/// </summary>
[MemoryDiagnoser]
[SimpleJob(RunStrategy.Monitoring, iterationCount: 1)]
public class GeneralSendTest
{
private Base _testData;
private IOperations _operations;
private ServerTransport _remote;
private Account acc;
private Client client;
private Project _project;
[GlobalSetup]
public async Task Setup()
{
TypeLoader.Initialize(typeof(Base).Assembly, typeof(Point).Assembly);
using var dataSource = new TestDataHelper();
await dataSource
.SeedTransport(
new Account() { serverInfo = new() { url = "https://latest.speckle.systems/" } },
"2099ac4b5f",
"30fb4cbe6eb2202b9e7b4a4fcc3dd2b6",
false
)
.ConfigureAwait(false);
SpeckleObjectDeserializer deserializer = new() { ReadTransport = dataSource.Transport };
string data = await dataSource.Transport.GetObject(dataSource.ObjectId).NotNull();
_testData = await deserializer.DeserializeAsync(data).NotNull();
_operations = TestDataHelper.ServiceProvider.GetRequiredService<IOperations>();
acc = TestDataHelper
.ServiceProvider.GetRequiredService<IAccountManager>()
.GetAccounts("https://latest.speckle.systems")
.First();
client = TestDataHelper.ServiceProvider.GetRequiredService<IClientFactory>().Create(acc);
_project = await client.Project.Create(
new($"General Send Test run {Guid.NewGuid()}", null, ProjectVisibility.Public)
);
_remote = TestDataHelper.ServiceProvider.GetRequiredService<IServerTransportFactory>().Create(acc, _project.id);
}
[Benchmark(Baseline = true)]
public async Task<string> Send_old()
{
using SQLiteTransport local = new();
var res = await _operations.Send(_testData, [_remote, local]);
return await TagVersion($"Send_old {Guid.NewGuid()}", res.rootObjId);
}
[Benchmark]
public async Task<string> Send_new()
{
var res = await _operations.Send2(new(acc.serverInfo.url), _project.id, acc.token, _testData);
return await TagVersion($"Send_new {Guid.NewGuid()}", res.RootId);
}
private async Task<string> TagVersion(string name, string objectId)
{
var model = await client.Model.Create(new(name, null, _project.id));
return await client.Version.Create(new(objectId, model.id, _project.id));
}
}