Esempio n. 1
0
		private void Report(BenchmarkResultSet result, BenchmarkParameters parameters)
		{
			Output("Report for benchmark:		{0}", result.Benchmark);
			Output("Bytes:				{0:#,#;;0} kb", result.TotalBytes / 1024);
			Output("Time (seconds):			{0:00}", result.ElapsedSeconds);
			Output("Rate:				{0}", result.Rate);
			Output("Operations:			{0:#,#;;0}", result.TotalOperations);
			Output("Operations per second:		{0:#,#;;0} op/s", result.TotalOperations / result.ElapsedSeconds);
			Output("Milliseconds per op:		{0:0.00000} ms/op", result.ElapsedMilliseconds / (double)result.TotalOperations);

			if (parameters.Histogram)
			{
				Output(result.Histogram.ToString());
			}

			if (result.Messages.Count > 0)
			{
				Output("Messages:");
				for (var index = 0; index < result.Messages.Count; index++)
				{
					var message = result.Messages[index];
					Output(string.Format("{0}. {1}", index + 1, message));
				}
			}

			Output(Constants.Separator);
		}
Esempio n. 2
0
		private async Task<BenchmarkResultSet> RunBenchmarkAsync(string benchmark, BenchmarkParameters parameters)
		{
			Debug.Assert(parameters.Method != null);

			var result = new BenchmarkResultSet(benchmark, parameters);

			var tasks = new Task<BenchmarkResult>[parameters.NumberOfThreads];
			for (var i = 0; i < parameters.NumberOfThreads; i++)
			{
				tasks[i] = parameters.Method(parameters);
			}

			await Task.WhenAll(tasks);

			for (var i = 0; i < parameters.NumberOfThreads; i++)
			{
				result.AddResult(i, tasks[i].Result);
			}

			return result;
		}