public void Run() { var duration = Duration.TotalSeconds; var threadCount = ParallelRunner.ThreadCount; using (Writer.Section($"Test settings:")) { Writer.AppendMetric("Duration", duration * 1000, "ms"); Writer.AppendMetric("Thread count", threadCount, ""); Writer.AppendMetric("Unit size", UnitAllocator.UnitSize, "B"); } Writer.AppendLine(); var totalCount = 0L; for (var pass = 0; pass < PassCount; pass++) { var runner = ParallelRunner.New(i => new UnitAllocator(Duration)); var allocators = runner.Run(); totalCount = Math.Max(totalCount, allocators.Sum(a => a.AllocationCount)); } var totalSize = totalCount * UnitAllocator.UnitSize; var totalSizeWithOverhead = totalCount * (UnitAllocator.UnitSize + GarbageAllocator.ObjectSize); using (Writer.Section($"Allocation speed:")) { Writer.AppendMetric("Operations per second", totalCount / Sizes.Mega / duration, "M/s"); // Writer.AppendMetric("Bytes per second", totalSize / duration / Sizes.GB, "GB/s"); // Writer.AppendMetric("Bytes per second (incl. overhead)", totalSizeWithOverhead / duration / Sizes.GB, "GB/s"); } Writer.AppendLine(); }
public static void AppendHistogram(this IndentedTextWriter writer, string title, double[] data, string unit, string format = "0.####", double[] percentiles = null) { percentiles = percentiles ?? DefaultPercentiles; IndentedTextWriter AppendLine(string s) => writer.AppendLine(s); IndentedTextWriter AppendMetric(string name, double value) => writer.AppendMetric(name, value, unit); using (writer.Section($"{title}")) { if (data.Length == 0) { AppendLine("No data."); return; } AppendLine("Min .. Max:"); using (writer.Indent()) { AppendMetric("Min", data.Min()); AppendMetric("Avg", data.Average()); AppendMetric("Max", data.Max()); } if (percentiles.Length > 0) { AppendLine("Percentiles:"); using (writer.Indent()) { var maxIndex = data.Length - 1; foreach (var p in percentiles) { AppendMetric($"{p:#.##}%", data[(int)(maxIndex * p / 100)]); } } } } }
public void Run(Options options) { // Applying options if (!string.IsNullOrEmpty(options.GCLatencyMode)) { GCSettings.LatencyMode = Enum.Parse <GCLatencyMode>(options.GCLatencyMode); } if (options.Duration.HasValue) { BurnTester.DefaultDuration = TimeSpan.FromSeconds(options.Duration.Value); } BurnTester.DefaultMaxSize = ArgumentHelper.ParseRelativeValue( options.MaxSize, BurnTester.DefaultMaxSize, true); ParallelRunner.ThreadCount = (int)ArgumentHelper.ParseRelativeValue( options.ThreadCount, ParallelRunner.ThreadCount, true); var tests = options.Tests?.ToLowerInvariant() ?? ""; var ramSizeGb = HardwareInfo.GetRamSize() ?? 4; var staticSetSizeGb = 0; if (!string.IsNullOrEmpty(options.StaticSetSize)) { tests += "b"; staticSetSizeGb = (int)ArgumentHelper.ParseRelativeValue(options.StaticSetSize, ramSizeGb, true); } var outputMode = options.OutputMode ?? "f"; if (outputMode == "f") { // Dumping environment info Writer.AppendValue("Launch parameters", string.Join(" ", Environment.GetCommandLineArgs().Skip(1))); using (Writer.Section("Software:")) { Writer.AppendValue("Runtime", ".NET Core"); using (Writer.Indent()) { Writer.AppendValue("Version", RuntimeInformation.FrameworkDescription); Writer.AppendValue("GC mode", GCInfo.GetGCMode()); } Writer.AppendValue("OS", $"{RuntimeInformation.OSDescription.Trim()} ({RuntimeInformation.OSArchitecture})"); } using (Writer.Section("Hardware:")) { var coreCountAddon = ParallelRunner.ThreadCount != Environment.ProcessorCount ? $", {ParallelRunner.ThreadCount} used by test" : ""; Writer.AppendValue("CPU", HardwareInfo.GetCpuModelName()); Writer.AppendValue("CPU core count", $"{Environment.ProcessorCount}{coreCountAddon}"); Writer.AppendValue("RAM size", $"{ramSizeGb:N0} GB"); } Writer.AppendLine(); } RunWarmup(); if (tests == "") { RunSpeedTest(); RunBurnTest("--- Stateless server (no static set) ---", 0); RunBurnTest("--- Worker / typical server (static set = 20% RAM) ---", (long)(ramSizeGb * Sizes.GB / 5)); RunBurnTest("--- Caching / compute server (static set = 50% RAM) ---", (long)(ramSizeGb * Sizes.GB / 2)); return; } if (tests.Contains("a")) { RunSpeedTest(); } if (tests.Contains("b")) { var title = $"--- Static set = {staticSetSizeGb} GB ({staticSetSizeGb * 100.0 / ramSizeGb:0.##} % RAM) ---"; RunBurnTest(title, (long)(staticSetSizeGb * Sizes.GB)); } }