public Result RunBatch(BenchTask task, int seconds) { DateTime start; DateTime end; // run one to eliminate possible startup overhead and do GC collection RunStep(); GC.Collect(); start = DateTime.Now; for (int i = 0; i < InitialSamples; i++) { RunStep(); } end = DateTime.Now; var initTs = end - start; int steps = (int)(seconds * 1000.0 * InitialSamples / Math.Max(1.0, initTs.TotalMilliseconds)); start = DateTime.Now; for (int i = 0; i < steps; i++) { RunStep(); } end = DateTime.Now; var ts = end - start; return(new Result { span = ts + initTs, steps = steps + InitialSamples, taskName = task.Name, measurementName = Name }); }
public Result RunBatch(BenchTask task, int milliseconds) { DateTime start = DateTime.Now; DateTime end; int i = 0; try { // run one to eliminate possible startup overhead and do GC collection RunStep(); GC.Collect(); start = DateTime.Now; for (i = 0; i < InitialSamples; i++) { RunStep(); } end = DateTime.Now; var initTs = end - start; int steps = CalculateSteps(milliseconds, initTs); start = DateTime.Now; for (i = 0; i < steps; i++) { RunStep(); } end = DateTime.Now; var ts = end - start; return(new Result { span = ts + initTs, steps = steps + InitialSamples, taskName = task.Name, measurementName = Name }); } catch (Exception ex) { end = DateTime.Now; var ts = end - start; Console.WriteLine(ex); return(new Result { span = ts, steps = i + InitialSamples, taskName = task.Name, measurementName = Name + " " + ex.Message }); } }
public string RunTasks() { if (resultsReturned) { return(""); } if (taskCounter == 0) { taskCounter++; Task = tasks[0]; return("Benchmark started<br>"); } if (runIdx >= Task.Measurements [measurementIdx].NumberOfRuns) { runIdx = 0; measurementIdx++; if (measurementIdx >= Task.Measurements.Length) { taskCounter++; if (taskCounter > tasks.Length) { resultsReturned = true; return(ResultsSummary()); } Task = tasks[taskCounter - 1]; } } runIdx++; return(Task.RunBatch(results, measurementIdx)); }
public async Task <Result> RunBatch(BenchTask task, int milliseconds) { DateTime start = DateTime.Now; DateTime end; try { // run one to eliminate possible startup overhead and do GC collection if (HasRunStepAsync) { await RunStepAsync(); } else { RunStep(); } GC.Collect(); start = DateTime.Now; for (currentStep = 0; currentStep < InitialSamples; currentStep++) { if (HasRunStepAsync) { await RunStepAsync(); } else { RunStep(); } } end = DateTime.Now; var initTs = end - start; int steps = CalculateSteps(milliseconds, initTs); start = DateTime.Now; for (currentStep = 0; currentStep < steps; currentStep++) { if (HasRunStepAsync) { await RunStepAsync(); } else { RunStep(); } } end = DateTime.Now; var ts = end - start; return(new Result { span = ts + initTs, steps = steps + InitialSamples, taskName = task.Name, measurementName = Name }); } catch (Exception ex) { end = DateTime.Now; var ts = end - start; Console.WriteLine(ex); return(new Result { span = ts, steps = currentStep + InitialSamples, taskName = task.Name, measurementName = Name + " " + ex.Message }); } }