Пример #1
0
 public void LogTestResult(string testName, TestStats stats)
 {
     if (_logTestResult != null)
     {
         _logTestResult(testName, _iterations, _concurrency, stats);
     }
 }
Пример #2
0
 private void LogTestResult(string testName, int iterations, int concurrency, TestStats stats)
 {
     Program.LogTestToConsole(testName, stats);
     if (_RawCsvOutput != TextWriter.Null)
     {
         _RawCsvOutput.WriteLine("\"{0}\",{1},{2},{3},{4},{5}", testName, iterations, concurrency, stats.Median.TotalMilliseconds, stats.Mean.TotalMilliseconds, stats.StdDev.TotalMilliseconds);
     }
     _Entries.Add(Tuple.Create(testName, iterations, concurrency, stats));
 }
Пример #3
0
 public static void LogTestToConsole(string testName, TestStats stats)
 {
     Console.WriteLine("{0,-45} {1,6:0.000}ms, {2,6:0.000}ms, {3,6:0.000}ms", testName, stats.Median.TotalMilliseconds, stats.Mean.TotalMilliseconds, stats.StdDev.TotalMilliseconds);
 }
Пример #4
0
        public void Run(int iterations, int concurrency)
        {
            // warmup
            foreach (var test in this)
            {
                var task = test.Iteration(iterations + 1);
                task.Wait();
            }

            //System.Threading.ThreadPool.SetMaxThreads(concurrency*2, concurrency*2);
            //System.Threading.ThreadPool.SetMinThreads(concurrency, concurrency);
            //System.Threading.ThreadPool.SetMaxThreads(concurrency * 2, concurrency * 2);

            if (concurrency == 1)
            {
                var rand = new Random();
                foreach (var test in this.OrderBy(ignore => rand.Next()))
                {
                    var watch = new Stopwatch();
                    for (int i = 1; i <= iterations; i++)
                    {
                        watch.Reset();
                        watch.Start();
                        var task = test.Iteration(i);
                        task.Wait();
                        watch.Stop();
                        test.Timings.Add(watch.Elapsed);
                    }
                    test.Teardown();
                }
            }
            else if (concurrency > iterations)
            {
                throw new InvalidOperationException(String.Format("Concurrency ({0}) exceeds iterations ({1})", concurrency, iterations));
            }
            else
            {
                Func <Test, int, Task> createTask = async(test, concurrencyIndex) =>
                {
                    var watch = new Stopwatch();
                    for (var i = concurrencyIndex; i < iterations; i += concurrency)
                    {
                        watch.Reset();
                        watch.Start();
                        var   work = test.Iteration(i);
                        await work;
                        watch.Stop();
                        test.Timings.Add(watch.Elapsed);
                    }
                };
                foreach (var test in this)
                {
                    var tasksToWaitOn = Enumerable.Range(1, concurrency).Select(i => createTask(test, i)).ToArray();
                    Task.WaitAll(tasksToWaitOn);
                    test.Teardown();
                }
            }


            foreach (var test in this.OrderBy(x => x.Timings.Sum()))
            {
                var mean      = test.Timings.Average();
                var testStats = new TestStats()
                {
                    Median = test.Timings.Median(),
                    Mean   = mean,
                    StdDev = test.Timings.StdDevFrom(mean)
                };
                _resultLogger(test.Name, testStats);
            }
        }