private void RunBenchmark(BenchmarkItem item) { double fastestRun = double.MaxValue; var watch = new Stopwatch(); int runsSinceLastBest = 0; while (runsSinceLastBest < item.RunsNeeded) { runsSinceLastBest++; item.Setup(); watch.Restart(); item.Run(); watch.Stop(); if (fastestRun > watch.Elapsed.TotalSeconds) { fastestRun = watch.Elapsed.TotalSeconds; runsSinceLastBest = 0; } } item.Time = fastestRun; item.Result = item.PrintResult(item.Time); }
internal BenchmarkItem BenchmarkTrigger(Trigger t) { int i = 0; BenchmarkItem bi = new BenchmarkItem(); bi.trig = t; string temp = "this is just a benchmark test string that has no bearing on anything important"; Context ctx = new Context(); ctx.plug = plug; Stopwatch st = Stopwatch.StartNew(); while (i < 10000) { long stTime = st.ElapsedTicks; if (backgroundWorker1.CancellationPending == true) { return(null); } t.CheckMatch(temp); bi.TimeOnMatch += st.ElapsedTicks - stTime; stTime = st.ElapsedTicks; t.Parent.PassesFilter(temp, temp); bi.TimeOnParent += st.ElapsedTicks - stTime; stTime = st.ElapsedTicks; if (t.Condition != null && t.Condition.Enabled == true) { t.Condition.CheckCondition(ctx, t.TriggerContextLogger, plug); } bi.TimeOnConditions += st.ElapsedTicks - stTime; i++; } st.Stop(); return(bi); }
public void Register(string name, Action setupAction, Action runAction, Func <double, string> resultPrinter, int runsNeeded = -1) { var benchmark = new BenchmarkItem { Name = name, Setup = setupAction, Run = runAction, PrintResult = resultPrinter, RunsNeeded = runsNeeded == -1 ? DefaultRunsNeeded : runsNeeded }; Benchmarks.Add(benchmark); }
public async Task <IActionResult> OnGetAsync() { Municipios = await _infoRepository.ListarMunicipios(); Elementos = await _infoRepository.ListarElementosIN(); if (!string.IsNullOrEmpty(CodigoMunicipio) && CompetenciaSelecionados.Length > 0 && ElementoSelecionados.Length > 0) { Municipio m = await _infoRepository.ListarMunicipios(CodigoMunicipio); Benchmark = new BenchmarkItem() { Elementos = Elementos.Where(x => ElementoSelecionados.Contains(x.CodigoElemento)).ToList(), Categorias = CompetenciaSelecionados, }; foreach (var en in ElementoSelecionados) { foreach (var c in CompetenciaSelecionados) { //ElementoNacional elementoNacional = await _infoRepository.ListarElementosNacionais(c); //ElementoEstadual elementoEstadual = await _infoRepository.ListarElementosEstaduais(m.UF, c); //decimal valorElementoNacional = GetPropValue(elementoNacional, en); //decimal valorElementoEstadual = GetPropValue(elementoEstadual, en); //decimal valorElementoMunicipal = GetPropValue(elementoMunicipal, en); Benchmark.Series.Add(new BenchmarkSerie() { name = en, //data = new decimal[] { valorElementoEstadual, valorElementoNacional } }); } } } return(Page()); }