Esempio n. 1
0
        public static string GetResultDetailsString(BenchmarkResult result, bool printThreadResults = false, TimePeriod periodForPerformanceDisplay = null, bool debug = false)
        {
            var writer = new StringWriter();

            PrintResultDetailsImpl(result: result,
                                   printThreadResults: printThreadResults,
                                   useColors: false,
                                   periodForPerformanceDisplay: periodForPerformanceDisplay,
                                   debug: debug,
                                   writer: writer);

            return writer.GetString();
        }
Esempio n. 2
0
 public static double CalculateExecutionsPerPeriod(uint completedExecutions, TimeSpan elapsedTime, TimePeriod period)
 {
     return ((double)completedExecutions) * period.Duration.TotalMilliseconds / elapsedTime.TotalMilliseconds;
 }
Esempio n. 3
0
        protected static void PrintResultDetailsImpl(BenchmarkResult result, bool printThreadResults, bool useColors, TimePeriod periodForPerformanceDisplay, bool debug, IWriter writer)
        {
            if(periodForPerformanceDisplay == null)
                periodForPerformanceDisplay = TimePeriod.Second;

            var foregroundColor = Console.ForegroundColor;

            try
            {
                if(useColors)
                    Console.ForegroundColor = ConsoleColor.Cyan;

                writer.WriteLine("Result: {0}", result.ResultName ?? "<no name assigned>");
                writer.WriteLine("Mode: {0}", result.Mode.ToFriendlyString());

                if(useColors)
                    Console.ForegroundColor = foregroundColor;

                if(debug)
                    writer.WriteLine("Test took {0}", result.CompleteElapsedTime);

                if(printThreadResults)
                {
                    if(useColors)
                        Console.ForegroundColor = ConsoleColor.Yellow;

                    writer.WriteLine("Single threads:");

                    if(useColors)
                        Console.ForegroundColor = foregroundColor;
                }

                uint completedExecutionsSum = 0; // debugging only, see below
                var elapsedTimeSum = TimeSpan.Zero;
                var executionsPerPeriodPerThread = new double[result.ThreadResults.Length];

                for(long i = 0; i < result.ThreadResults.Length; ++i)
                {
                    double executionsPerPeriod = CalculateExecutionsPerPeriod(result.ThreadResults[i].CompletedExecutions,
                                                                              result.ThreadResults[i].CompleteElapsedTime,
                                                                              periodForPerformanceDisplay);

                    if(printThreadResults)
                    {
                        if(useColors)
                            Console.ForegroundColor = ConsoleColor.Yellow;

                        writer.WriteLine("- Thread #{0}", i + 1);

                        if(useColors)
                            Console.ForegroundColor = foregroundColor;

                        writer.WriteLine("  Took {0}", result.ThreadResults[i].CompleteElapsedTime);
                        writer.WriteLine("  Executed {0} times", result.ThreadResults[i].CompletedExecutions);
                        writer.WriteLine("  {0:#.##} executions/{1}{2}",
                                          executionsPerPeriod,
                                          periodForPerformanceDisplay.Name,
                                          result.Mode == BenchmarkMode.USER_SIMULATION
                                              ? " (user simulation mode: waiting time not considered)"
                                              : string.Empty);
                        writer.WriteLine("  One execution took {0} in average", result.ThreadResults[i].AverageTimePerExecution);

                        if(debug)
                            writer.WriteLine("  Stop reason {0}", result.ThreadResults[i].StopReason);

                        if(result.ThreadResults[i].FirstUncountedException != null ||
                           (result.ExceptionMode == ExceptionMode.COUNT &&
                            result.ThreadResults[i].FirstCountedException != null))
                        {
                            if(useColors)
                                Console.ForegroundColor = ConsoleColor.Red;

                            writer.WriteLine("  Test execution led to an exception in this thread:");

                            if(result.ThreadResults[i].FirstUncountedException != null)
                                writer.WriteLine("  first uncounted: {0}",
                                                 FormatException(result.ThreadResults[i].FirstUncountedException));
                            if(result.ExceptionMode == ExceptionMode.COUNT &&
                               result.ThreadResults[i].FirstCountedException != null)
                            {
                                writer.WriteLine("  first counted: {0}",
                                                 FormatException(result.ThreadResults[i].FirstCountedException));
                                writer.WriteLine("  number of counted exceptions: {0}",
                                                 result.ThreadResults[i].ExceptionCount);
                            }

                            if(useColors)
                                Console.ForegroundColor = foregroundColor;
                        }
                    }

                    completedExecutionsSum += result.ThreadResults[i].CompletedExecutions;
                    elapsedTimeSum += result.ThreadResults[i].CompleteElapsedTime;
                    executionsPerPeriodPerThread[i] = executionsPerPeriod;
                }

                if(result.HasErrors)
                {
                    if(useColors)
                        Console.ForegroundColor = ConsoleColor.Red;

                    writer.WriteLine("Test execution led to an exception in at least one thread:");

                    if(result.FirstUncountedException != null)
                        writer.WriteLine("  first uncounted: {0}", FormatException(result.FirstUncountedException));
                    if(result.ExceptionMode == ExceptionMode.COUNT && result.FirstCountedException != null)
                    {
                        writer.WriteLine("  first counted: {0}", FormatException(result.FirstCountedException));
                        writer.WriteLine("  total number of counted exceptions: {0}", result.ExceptionCount);
                    }

                    return;
                }

                Debug.Assert(completedExecutionsSum == result.CompletedExecutions);

                if(useColors)
                    Console.ForegroundColor = ConsoleColor.Magenta;

                writer.WriteLine("Overall:");

                if(useColors)
                    Console.ForegroundColor = foregroundColor;

                var averageTimeTaken = new TimeSpan(elapsedTimeSum.Ticks / result.ThreadResults.Length);
                var executionsPerPeriodSum = executionsPerPeriodPerThread.Sum();

                writer.WriteLine("  Each thread took {0} in average", averageTimeTaken);
                writer.WriteLine("  Executed {0} times altogether", result.CompletedExecutions);
                if(result.Mode == BenchmarkMode.BENCHMARK)
                    writer.WriteLine("  {0:#.##} executions/{1}",
                                     executionsPerPeriodSum,
                                     periodForPerformanceDisplay.Name);
                writer.WriteLine("  One execution took {0} in average", result.AverageTimePerExecution);

                // If executions/second > 100000
                if((executionsPerPeriodSum * periodForPerformanceDisplay.Duration.TotalSeconds) > 100000)
                {
                    if(useColors)
                        Console.ForegroundColor = ConsoleColor.Red;

                    writer.WriteLine("Warning: High number of executions/second. Note that NSiege should not be " +
                                     "used for very short tests because the CPU time for the timing might create " +
                                     "a bias.");
                }
            }
            finally
            {
                if(useColors)
                    Console.ForegroundColor = foregroundColor;
            }
        }
Esempio n. 4
-1
 public static void PrintResultDetails(BenchmarkResult result, bool printThreadResults = false, bool useColors = false, TimePeriod periodForPerformanceDisplay = null, bool debug = false)
 {
     PrintResultDetailsImpl(result: result,
                            printThreadResults: printThreadResults,
                            useColors: false,
                            periodForPerformanceDisplay: periodForPerformanceDisplay,
                            debug: debug,
                            writer: new ConsoleWriter());
 }