From 14fbb042b5d3b91af7f8e6f80fe9d2355d64fbd5 Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Tue, 14 Mar 2023 22:15:51 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B8=20=D0=B7=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=80=D0=B0=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WorkTime/WorkTime/Controller.cs | 8 +------ WorkTime/WorkTime/Program.cs | 39 ++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/WorkTime/WorkTime/Controller.cs b/WorkTime/WorkTime/Controller.cs index ac6bdb7..53a52b0 100644 --- a/WorkTime/WorkTime/Controller.cs +++ b/WorkTime/WorkTime/Controller.cs @@ -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 diff --git a/WorkTime/WorkTime/Program.cs b/WorkTime/WorkTime/Program.cs index 52e7e95..08da5e4 100644 --- a/WorkTime/WorkTime/Program.cs +++ b/WorkTime/WorkTime/Program.cs @@ -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; + } } } \ No newline at end of file