当前位置: 首页>>代码示例>>C#>>正文


C# Benchmark.Run方法代码示例

本文整理汇总了C#中Benchmark.Run方法的典型用法代码示例。如果您正苦于以下问题:C# Benchmark.Run方法的具体用法?C# Benchmark.Run怎么用?C# Benchmark.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Benchmark的用法示例。


在下文中一共展示了Benchmark.Run方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SmokeTest

        public void SmokeTest()
        {
            var target = new Benchmark();
            target.Duration = TimeSpan.FromSeconds(2);
            target.Threads = 4;
            target.AddComponent("Commands", RandomSleep(10, 50));
            target.AddComponent("Queries", RandomSleep(2,5), 10);
            BenchmarkResult result = target.Run();

            Trace.WriteLine("Elapsed: " + result.Elapsed);

            var stats = result.StatisticsByKey();
            stats.Add("Totals", result.TotalStatistics());
            foreach (var stat in stats)
            {
                Trace.WriteLine(stat.Key);
                if (stat.Key != "Totals") Trace.WriteLine("Weight: " + result.Weights[stat.Key]);
                Trace.WriteLine("count  : " + stat.Value.Count);
                Trace.WriteLine("sum    : " + stat.Value.Sum);
                Trace.WriteLine("avg    : " + stat.Value.MeanAverage);
                Trace.WriteLine("min    : " + stat.Value.Min);
                Trace.WriteLine("max    : " + stat.Value.Max);
                Trace.WriteLine("TPS    : " + stat.Value.Count / result.Elapsed.TotalSeconds);
                Trace.WriteLine("Percentiles: ");
                foreach (var p in new[]{10,20,30,40,50,60,70,80,90,99})
                {
                    var percentile = stat.Value.Percentile(p);
                    Trace.WriteLine( p + "\t" + percentile);
                }
                Trace.WriteLine("");
                Trace.Write("Histogram: ");
                foreach (var count in stat.Value.Histogram(10))
                {
                    Trace.Write(count + ", ");
                }
                Trace.WriteLine("");

                Assert.AreEqual(stat.Value.Count, stat.Value.Histogram(10).Sum());
                Assert.AreEqual(stat.Value.Count, stat.Value.Histogram(20).Sum());
                Assert.AreEqual(stat.Value.Count, stat.Value.Histogram(30).Sum());

            }
        }
开发者ID:avgx,项目名称:OrigoDB,代码行数:43,代码来源:BenchmarkTests.cs

示例2: btnRun_Click

    protected void btnRun_Click(object sender, EventArgs e)
    {
        // Get the number of iterations
        int iterations = ValidationHelper.GetInteger(txtIterations.Text, 0);
        if (iterations <= 0)
        {
            ShowError(GetString("macros.benchmark.invaliditerations"));
            return;
        }

        // Prepare the benchmark
        var benchmark = new Benchmark<string>(Execute)
        {
            SetupFunc = Setup,
            Iterations = iterations,
            TearDownFunc = TearDown
        };

        // Run the benchmark
        benchmark.Run();

        // Append expression to the results
        var text = editorElem.Text;
        var results = benchmark.GetReport();

        results += String.Format(
        @"
        Evaluated text:
        ---------------
        {0}
        ",
            text
        );

        // Update UI
        editorElem.Text = text;
        txtOutput.Text = benchmark.Result;
        txtResults.Text = results;
    }
开发者ID:kbuck21991,项目名称:kentico-blank-project,代码行数:39,代码来源:Benchmark.aspx.cs


注:本文中的Benchmark.Run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。