diff --git a/Persistence.Benchmark/Persistence.Benchmark.csproj b/Persistence.Benchmark/Persistence.Benchmark.csproj
index 0a8f325..8649307 100644
--- a/Persistence.Benchmark/Persistence.Benchmark.csproj
+++ b/Persistence.Benchmark/Persistence.Benchmark.csproj
@@ -10,6 +10,8 @@
+
+
diff --git a/Persistence.Benchmark/Program.cs b/Persistence.Benchmark/Program.cs
index d887886..a9285c2 100644
--- a/Persistence.Benchmark/Program.cs
+++ b/Persistence.Benchmark/Program.cs
@@ -8,11 +8,7 @@ public class Program
{
private static void Main(string[] args)
{
- //var host = BenchmarkSwitcher.FromAssembly(typeof(Persistence.API.Program).Assembly);
- //host.Run
-
- //System.Console.OutputEncoding = System.Text.Encoding.UTF8;
-
- BenchmarkRunner.Run();
+ var count = Convert.ToInt32(Console.ReadLine());
+ WitsDataBenchmark.ExecuteTest(count).Wait();
}
}
\ No newline at end of file
diff --git a/Persistence.Benchmark/Tests/BaseIntegrationTest.cs b/Persistence.Benchmark/Tests/BaseIntegrationTest.cs
deleted file mode 100644
index 1fe9ed8..0000000
--- a/Persistence.Benchmark/Tests/BaseIntegrationTest.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using Microsoft.Extensions.DependencyInjection;
-using DD.Persistence.Database;
-using DD.Persistence.Database.Model;
-using Xunit;
-
-namespace Persistence.Benchmark;
-public abstract class BaseIntegrationTest : IClassFixture, IDisposable
-{
- protected readonly IServiceScope scope;
-
- protected readonly PersistenceDbContext dbContext;
-
- protected BaseIntegrationTest(WebAppFactoryFixture factory)
- {
- scope = factory.Services.CreateScope();
-
- dbContext = scope.ServiceProvider.GetRequiredService();
- }
-
- public void Dispose()
- {
- scope.Dispose();
- dbContext.Dispose();
- GC.SuppressFinalize(this);
- }
-}
diff --git a/Persistence.Benchmark/Tests/WitsDataBenchmark.cs b/Persistence.Benchmark/Tests/WitsDataBenchmark.cs
new file mode 100644
index 0000000..0c6e18b
--- /dev/null
+++ b/Persistence.Benchmark/Tests/WitsDataBenchmark.cs
@@ -0,0 +1,124 @@
+using DD.Persistence.Client;
+using DD.Persistence.Models;
+using Microsoft.Extensions.DependencyInjection;
+using NPlot;
+using System.Diagnostics;
+
+namespace Persistence.Benchmark.Tests;
+
+public static class WitsDataBenchmark
+{
+ private const string discriminatorId = "fef21bfd-e924-473d-b6c8-e4377e38245d";
+
+ 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();
+
+ // Create a new bitmap plot surface
+ var plotSurface = new NPlot.Bitmap.PlotSurface2D(800, 600);
+
+ // Create a line plot
+ var linePlot = new LinePlot();
+
+ var abscissaData = new List() {};
+ var ordinateData = new List() {};
+
+ var saved = 0;
+ foreach (var item in data) {
+ var time = sw.Elapsed;
+
+ sw.Start();
+ var response = await client.AddRange(item, source.Token);
+ sw.Stop();
+
+ Console.WriteLine($"Сохранено: {response.ToString()}");
+ saved = saved + response;
+ abscissaData.Add(saved/100_000);
+
+ Console.WriteLine($"Затрачено времени на сохранение части: {sw.Elapsed - time}");
+ ordinateData.Add((double)(sw.Elapsed - time).TotalSeconds);
+ }
+
+ Console.WriteLine($"Затрачено времени на сохранение: {sw.Elapsed}");
+
+ // Add the line plot to the plot surface
+ linePlot.AbscissaData = abscissaData;
+ linePlot.OrdinateData = ordinateData;
+ plotSurface.Add(linePlot);
+
+ // Customize the plot (e.g., titles, labels)
+ plotSurface.Title = "График";
+ plotSurface.XAxis1.Label = "Количество сохраненных записей в БД (100.000)";
+ plotSurface.YAxis1.Label = "Время на сохранение 100.000 записей (сек.)";
+
+ // Refresh the plot to render it
+ plotSurface.Refresh();
+
+ #pragma warning disable
+ // Save the plot as a PNG image
+ plotSurface.Bitmap.Save("C:\\Users\\fremo\\source\\repos\\persistence\\Persistence.Benchmark\\plot.png", System.Drawing.Imaging.ImageFormat.Png);
+ #pragma warning enable
+
+ var dis = Guid.Parse(discriminatorId);
+ var date = DateTime.Now.AddDays(-1);
+
+ sw = new Stopwatch();
+ sw.Start();
+ var get = await client.GetPart(dis, 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 / 100_000 + (countToCreate % 100_000 == 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 < 100; i++)
+ {
+ var timestamped = DateTimeOffset.UtcNow;
+ var random = new Random();
+ 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;
+ }
+}
diff --git a/Persistence.Benchmark/Tests/WitsDataTest.cs b/Persistence.Benchmark/Tests/WitsDataTest.cs
deleted file mode 100644
index 0fcdc59..0000000
--- a/Persistence.Benchmark/Tests/WitsDataTest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using BenchmarkDotNet.Attributes;
-using BenchmarkDotNet.Engines;
-using Microsoft.Extensions.DependencyInjection;
-using DD.Persistence.Client;
-using DD.Persistence.Client.Clients;
-using DD.Persistence.Client.Clients.Interfaces;
-using DD.Persistence.Models;
-
-namespace Persistence.Benchmark.Tests;
-
-[SimpleJob(RunStrategy.ColdStart, 1)]
-public class WitsDataTest
-{
- private readonly IWitsDataClient client;
- public IEnumerable data;
- public WitsDataTest()
- {
- var factory = new WebAppFactoryFixture();
-
- var scope = factory.Services.CreateScope();
- var persistenceClientFactory = scope.ServiceProvider
- .GetRequiredService();
- client = persistenceClientFactory.GetWitsDataClient();
-
- //data = GenerateData(1_000_000);
- }
-
- [Benchmark]
- [IterationCount(1)]
- public async Task WithCompositePk()
- {
- try
- {
- //var data = GenerateData(1_000_000);
- var source = new CancellationTokenSource(TimeSpan.FromSeconds(6000));
- var response = await client.AddRange(data, source.Token);
- Console.WriteLine(response.ToString());
- //var discriminatorId = data.FirstOrDefault()!.DiscriminatorId;
- //var date = DateTimeOffset.UtcNow.AddDays(-1);
- //Console.WriteLine(date.ToString());
-
- //var test = await client.GetPart(discriminatorId, date);
- //Console.WriteLine(test.FirstOrDefault()?.DiscriminatorId.ToString());
- }
- catch (Exception ex) {
- Console.WriteLine(ex.Message);
- }
- }
-
- [GlobalSetup]
- public void GenerateData()
- {
- int countToCreate = 80_000_000;
-
- var dtos = new List();
-
- for (var j = 0; j < countToCreate / 100 ; j++)
- {
- for (var i = 0; i < countToCreate && i < 100; i++)
- {
- var discriminatorId = Guid.NewGuid();
- var timestamped = DateTimeOffset.UtcNow;
- var random = new Random();
- dtos.Add(new WitsDataDto()
- {
- DiscriminatorId = discriminatorId,
- Timestamped = timestamped.AddSeconds(i),
- Values = new List()
- {
- new WitsValueDto()
- {
- RecordId = i + 1,
- ItemId = i + 1,
- Value = random.Next(1, 100)
- }
- }
- });
- }
- }
-
- data = dtos;
- }
-}
diff --git a/Persistence.Benchmark/WebAppFactoryFixture.cs b/Persistence.Benchmark/WebAppFactoryFixture.cs
index ad7a0a3..8741156 100644
--- a/Persistence.Benchmark/WebAppFactoryFixture.cs
+++ b/Persistence.Benchmark/WebAppFactoryFixture.cs
@@ -50,7 +50,6 @@ public class WebAppFactoryFixture : WebApplicationFactory();
- //dbContext.Database.SetCommandTimeout(5);
dbContext.Database.EnsureCreatedAndMigrated();
dbContext.SaveChanges();
});