using DD.Persistence.Client; using DD.Persistence.Models; using Microsoft.Extensions.DependencyInjection; using System.Diagnostics; namespace Persistence.Benchmark.Tests; public static class WitsDataBenchmark { private const string discriminatorId = "fef21bfd-e924-473d-b6c8-e4377e38245d"; private const int chunkSize = 25_000; public static async Task ExecuteTest(int count) { try { var factory = new WebAppFactoryFixture(); var scope = factory.Services.CreateScope(); var persistenceClientFactory = scope.ServiceProvider .GetRequiredService(); var client = persistenceClientFactory.GetWitsDataClient(); var source = new CancellationTokenSource(TimeSpan.FromSeconds(6000)); //var data = GenerateData(count); var sw = new Stopwatch(); //var saved = 0; //foreach (var item in data) //{ // var time = sw.Elapsed; // sw.Start(); // var response = await client.AddRange(item, source.Token); // sw.Stop(); // saved = saved + response; // Console.WriteLine($"Сохранено: {saved.ToString()}"); //} //Console.WriteLine($"Затрачено времени на сохранение: {sw.Elapsed}"); var discriminator = Guid.Parse(discriminatorId); var date = DateTime.Now.AddDays(-31); Console.WriteLine($"\nВычитка..."); sw = new Stopwatch(); sw.Start(); var get = await client.GetPart(discriminator, date, count, source.Token); sw.Stop(); Console.WriteLine($"Затрачено времени на вычитку: {sw.Elapsed}"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } private static IEnumerable> GenerateData(int countToCreate) { var result = new List>(); int enumerableCount = countToCreate / chunkSize + (countToCreate % chunkSize == 0 ? 0 : 1); for (var k = 0; k < enumerableCount; k++) { var dtos = new List(); for (var j = 0; j < 1000; j++) { for (var i = 0; i < chunkSize / 1000; i++) { var random = new Random(); var timestamped = DateTimeOffset.UtcNow.AddSeconds(random.Next(1, 60 * 60 * 24 * 30) * -1); dtos.Add(new WitsDataDto() { DiscriminatorId = Guid.Parse(discriminatorId), Timestamped = timestamped.AddSeconds(i), Values = new List() { new WitsValueDto() { RecordId = i + 1, ItemId = i + 1, Value = random.Next(1, 100) } } }); } } result.Add(dtos); } return result; } }