добавлена возможность тестирования и замера времени

This commit is contained in:
m1aksim1 2023-03-14 22:15:51 +04:00
parent fd1f8e103b
commit 14fbb042b5
2 changed files with 39 additions and 8 deletions

View File

@ -1,10 +1,4 @@
using Microsoft.EntityFrameworkCore;
using WorkTime.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WorkTime.Models;
using ConsoleTableExt;
namespace WorkTime

View File

@ -1,4 +1,4 @@
using WorkTime;
using ConsoleTableExt;
using WorkTime.Models;
using System.Diagnostics;
@ -55,5 +55,42 @@ namespace WorkTime
}
} while (operation != "0");
}
public static void Test(Controller controller, CourseContext context)
{
Random r = new Random();
string name = "";
for (int i = 0; i < 7; i++)
name += (char)r.Next(3, 255);
Worker worker = new()
{
Name = name[..7],
PostId = r.Next(1,context.Posts.Last().Id),
};
var result = new[]
{
new { Name = "1", timems = MeasureTime(controller.GetWorkers)},
new { Name = "2", timems = MeasureTime(controller.GetProject)},
new { Name = "3", timems = MeasureTime(controller.GetSalary)},
new { Name = "4", timems = MeasureTime(() => controller.GetSalaryOnCurrentMonth())},
new { Name = "5", timems = MeasureTime(controller.GetPosts)},
new { Name = "6", timems = MeasureTime(() => controller.AddWorker(worker))},
}.ToList();
ConsoleTableBuilder.From(result).ExportAndWriteLine();
}
public static double MeasureTime(Action action, int count = 10)
{
long sumTime = 0;
Stopwatch stopwatch = new();
for (int i = 0; i < count; i++)
{
stopwatch.Start();
action.Invoke();
stopwatch.Stop();
sumTime += stopwatch.ElapsedMilliseconds;
}
return sumTime / count;
}
}
}