Exemplo n.º 1
0
        public static void Run()
        {
            CountingScenarioFactory scenarioFactory = new CountingScenarioFactory();

            StrategyBuilder strategy = new StrategyBuilder()
                                       .SetScenario(scenarioFactory)
                                       .SetThreading(new FixedThreadCount(4))
                                       .SetLimit(new TimeLimit(TimeSpan.FromSeconds(10)));


            // Increase TimeLimit precision
            LoadRunnerEngine engine = strategy.Build();

            engine.HeartBeatMs = 1;

            Stopwatch watch = new Stopwatch();

            watch.Start();
            engine.Run();
            watch.Stop();

            scenarioFactory.PrintSum();
            Console.WriteLine($@"TPS {scenarioFactory.GetSum() / watch.Elapsed.TotalSeconds:N}");
            Console.WriteLine(watch.Elapsed.ToString("g"));

            /*
             *  i5-4670
             *
             * Unoptimized build
             * 0 15887088
             * 1 13794690
             * 2 16120714
             * 3 13965244
             * -------
             * 59767736
             * TPS 5 873 963,09
             *
             * Optimized build
             * 0:00:10,0204332
             * 0 20196083
             * 1 20441812
             * 2 20276545
             * 3 20205667
             * -------
             * 81120107
             * TPS 8 095 469,07
             */
        }
Exemplo n.º 2
0
        public static void Run()
        {
            HistogramAggregator aggregator = new HistogramAggregator()
                                             .Add(new CountMetric())
                                             .Add(new FuncMetric <TimeSpan>("max", TimeSpan.Zero, (s, result) => s < result.IterationStarted ? result.IterationStarted : s));

            AssertIterationIdsAggregator idsValidator = new AssertIterationIdsAggregator();

            int streamCount = 0;
            StreamAggregator streamAggregator = new StreamAggregator(results => streamCount = results.Count());

            CountingScenarioFactory factory = new CountingScenarioFactory();

            StrategyBuilder strategy = new StrategyBuilder()
                                       .SetScenario(factory)
                                       .SetThreading(new FixedThreadCount(16))
                                       .SetLimit(new TimeLimit(TimeSpan.FromSeconds(12)))
                                       .SetAggregator(aggregator, idsValidator, streamAggregator);


            Stopwatch sw = new Stopwatch();

            sw.Start();
            strategy.Build().Run();
            sw.Stop();

            Console.WriteLine(JsonConvert.SerializeObject(aggregator.BuildResultsObjects(), Formatting.Indented));
            factory.PrintSum();
            int      expected      = factory.GetSum();
            int      actual        = (int)aggregator.BuildResults().Data[0][1];
            TimeSpan lastIteration = (TimeSpan)aggregator.BuildResults().Data[0][3];

            Console.WriteLine($@"TPS {expected / lastIteration.TotalSeconds:N}");
            Console.WriteLine($@"Last iteration ended at: {lastIteration:g}");
            Console.WriteLine($@"Aggregator catchup took: {(sw.Elapsed-lastIteration):g}");
            Console.WriteLine();
            Console.WriteLine($@"{expected}/{actual} & {streamCount} ? {expected==actual} && {expected==streamCount}");
            Console.WriteLine();
            idsValidator.PrintResults();
        }