public async Task <ActionResult <CalculationLog> > PostCalculationLog(CalculationLog calculationLog) { calculationLog.PerformCalc(); _context.Logs.Add(calculationLog); await _context.SaveChangesAsync(); return(calculationLog); }
public void TheHashcodeFactorOf25Is1234ToMakeTheHashEndOn0000() { // Arrange var calculator = new Sha256HashFactorCalculator(1); var log = new CalculationLog(); // Act calculator.Calculate(25, log); // Assert log.Items.Single().Result.Should().Be(1494000); }
public void TheHashcodeFactorOf25Is4153602ToMakeHashEndWith00000() { // Arrange var calculator = new Md5HashFactorCalculator(1); var log = new CalculationLog(); // Act calculator.Calculate(25, log); // Assert log.Items.Single().Result.Should().Be(4153602); }
public void TheFirstPrimeIs2() { // Arrange var calculator = new PrimeCalculator(1); var log = new CalculationLog(); // Act calculator.Calculate(1, log); // Assert log.Items.Single().Result.Should().Be(2); }
public void TheSquareOf15Is225() { // Arrange var calculator = new SquareCalculator(1); var log = new CalculationLog(); // Act calculator.Calculate(15, log); // Assert log.Items.Single().Result.Should().Be(225); }
public CalculationLog Calculate(int x) { var t = DateTime.Now; var log = new CalculationLog(); log.StartThreadId = Thread.CurrentThread.ManagedThreadId; _calculators.ForEach(c => c.Calculate(x, log)); log.MilliSeconds = (DateTime.Now - t).TotalMilliseconds; log.EndThreadId = Thread.CurrentThread.ManagedThreadId; return(log); }
public override void Calculate(int x, CalculationLog log) { var t = DateTime.Now; var y = x * x; log.Items.Add(new CalculationLogItem { Number = Number, Result = y, Name = GetType().Name, MilliSeconds = (DateTime.Now - t).TotalMilliseconds, ThreadId = Thread.CurrentThread.ManagedThreadId }); }
public CalculationLog ParallelCalculate(int x) { var t = DateTime.Now; var log = new CalculationLog(); log.StartThreadId = Thread.CurrentThread.ManagedThreadId; Parallel.ForEach(_calculators, calculator => { calculator.Calculate(x, log); }); log.MilliSeconds = (DateTime.Now - t).TotalMilliseconds; log.EndThreadId = Thread.CurrentThread.ManagedThreadId; return(log); }
public async Task <CalculationLog> AsyncWithTaskCalculate(int x) { var t = DateTime.Now; var log = new CalculationLog(); log.StartThreadId = Thread.CurrentThread.ManagedThreadId; foreach (var calculator in _calculators) { await Task.Run(() => calculator.Calculate(x, log)); } log.MilliSeconds = (DateTime.Now - t).TotalMilliseconds; log.EndThreadId = Thread.CurrentThread.ManagedThreadId; return(log); }
public CalculationLogModel(CalculationLog log, int number, string method, int threadId) : this(number) { ControllerStartThreadId = Thread.CurrentThread.ManagedThreadId; ControllerEndThreadId = Thread.CurrentThread.ManagedThreadId; EndThreadId = log.EndThreadId; StartThreadId = log.StartThreadId; MilliSeconds = log.MilliSeconds; Items = new List <CalculationLogItemModel>(); log.Items.ForEach(x => Items.Add(new CalculationLogItemModel { Number = x.Number, MilliSeconds = x.MilliSeconds, Result = x.Result, ThreadId = x.ThreadId, Name = x.Name })); Method = method; }
private void LogEnd(string method, CalculationLog log, int n) { var text = ResultTextbox.Lines.ToList(); text.Add($" ---- CONTINUE: {method} ({n}) ----"); text.Add($" Form thread ID: {Thread.CurrentThread.ManagedThreadId}"); text.Add($" DomainService thread ID: {log.StartThreadId}"); var i = 0; foreach (var item in log.Items) { text.Add($" {++i}. Thread ID: {(item.ThreadId.ToString()+new string(' ',2)).Substring(0,2)} {(item.Name+new string(' ',32)).Substring(0,32)} ({NumberTextBox.Text}) {(item.Result.ToString() + new string(' ', 12)).Substring(0,12)}{item.MilliSeconds} ms"); } text.Add($" DomainService thread ID: {log.EndThreadId}"); text.Add($" Elapsed time (s): {Math.Round(log.MilliSeconds/1000,2,MidpointRounding.AwayFromZero)}"); text.Add($""); ResultTextbox.Lines = text.ToArray(); }
public override void Calculate(int x, CalculationLog log) { var t = DateTime.Now; var y = 0; using (SHA256 sha256Hash = SHA256.Create()) { while (!IsFactor(x, ++y, sha256Hash)) { } } log.Items.Add(new CalculationLogItem { Number = Number, Result = y, Name = GetType().Name, MilliSeconds = (DateTime.Now - t).TotalMilliseconds, ThreadId = Thread.CurrentThread.ManagedThreadId }); }
public override void Calculate(int x, CalculationLog log) { var t = DateTime.Now; var count = 0; var y = 1; while (count < x) { if (IsPrime(++y)) { count++; } } log.Items.Add(new CalculationLogItem { Number = Number, Result = y, Name = GetType().Name, MilliSeconds = (DateTime.Now - t).TotalMilliseconds, ThreadId = Thread.CurrentThread.ManagedThreadId }); }
public async Task AsyncCalculate(int x, CalculationLog log) { Calculate(x, log); }
public abstract void Calculate(int x, CalculationLog log);