public Timings Generate() { var combinations = new Dictionary <string, RunDescription>() { { "legacy csproj (net461)", new RunDescription { ProjectFile = "Out_legacy.csproj", } }, { "net461", new RunDescription { ProjectFile = "Out_net461.csproj", } }, { "netstandard2.0 libraries", new RunDescription { ProjectFile = "Out_net461_consume_standard.csproj", } }, { "netcoreapp2.0", new RunDescription { ProjectFile = "Out_netcoreapp2.0.csproj", } }, }; var timings = new Timings { DotnetVersion = DotnetVersion(), DotnetFileVersion = DotnetFileVersion(), }; DotnetSdkVersion(timings); var runCount = 5; var outFolder = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\Out")); var totalRuns = runCount * combinations.Keys.Count; var currentRun = 0; foreach (var description in combinations.Keys) { var timing = new Timing { Description = description, }; var runDescription = combinations[description]; var runTimes = new List <Timing>(); for (var i = 0; i < runCount; i++) { currentRun++; Console.WriteLine($"\n\nRun {currentRun} of {totalRuns} {description} run {i + 1} of {runCount}\n"); var runTime = Time(outFolder, runDescription); runTimes.Add(runTime); } timing.Build = TimeSpan.FromTicks(runTimes.Sum(rt => rt.Build.Ticks) / runTimes.Count); timing.IncrementalBuildWithoutChange = TimeSpan.FromTicks(runTimes.Sum(rt => rt.IncrementalBuildWithoutChange.Ticks) / runTimes.Count); timing.IncrementalBuildWithChange = TimeSpan.FromTicks(runTimes.Sum(rt => rt.IncrementalBuildWithChange.Ticks) / runTimes.Count); timings.Frameworks.Add(timing); } return(timings); }
private static void ReportToConsole(Timings timings) { Console.WriteLine($"\n\n\n"); Console.WriteLine($"Timing Results"); Console.WriteLine($"==============\n"); Console.WriteLine($"dotnet.exe --version: {timings.DotnetVersion}"); Console.WriteLine($"dotnet.exe: {timings.DotnetFileVersion}"); Console.WriteLine($"\nSDK:"); Console.WriteLine($"{timings.SdkVersion}"); Console.WriteLine($"{timings.SdkBuildVersion}"); Console.WriteLine(); Console.WriteLine("Description Build Incremental Incremental "); Console.WriteLine(" (with change)(no changes) "); Console.WriteLine("-----------------------------------------------------------------"); foreach (var timing in timings.Frameworks) { Console.WriteLine($"{timing.Description.PadRight(25)} {Seconds(timing.Build).PadRight(12)} {Seconds(timing.IncrementalBuildWithChange).PadRight(12)} {Seconds(timing.IncrementalBuildWithoutChange).PadRight(12)}"); } Console.WriteLine("\nMultiplier\n"); long?baselineBuild = null; long?baselineIncrementalWithoutChange = null; long?baselineIncrementalWithChange = null; foreach (var timing in timings.Frameworks) { var buildTicks = timing.Build.Ticks; var incrementalWithoutChangeTicks = timing.IncrementalBuildWithoutChange.Ticks; var incrementalWithChangeTicks = timing.IncrementalBuildWithChange.Ticks; baselineBuild = baselineBuild ?? buildTicks; baselineIncrementalWithoutChange = baselineIncrementalWithoutChange ?? incrementalWithoutChangeTicks; baselineIncrementalWithChange = baselineIncrementalWithChange ?? incrementalWithChangeTicks; var buildMultiplier = buildTicks / (double)baselineBuild.Value; var incrementalWithoutChangeMultiplier = incrementalWithoutChangeTicks / (double)baselineIncrementalWithoutChange; var incrementalWithChangeMultiplier = incrementalWithChangeTicks / (double)baselineIncrementalWithChange; Console.WriteLine($"{timing.Description.PadRight(25)} {Multiplier(buildMultiplier).PadRight(12)} {Multiplier(incrementalWithChangeMultiplier).PadRight(12)} {Multiplier(incrementalWithoutChangeMultiplier).PadRight(12)}"); } }
private void DotnetSdkVersion(Timings timings) { var info = Exec.GetOutput(Path.GetDirectoryName(DotnetExe), DotnetExe, "--info"); var lastLines = info.Split("\n") .Where(l => l.Trim().Length > 0) .TakeLast(2) .ToList(); if (lastLines.Count < 1) { return; } timings.SdkVersion = lastLines[0]; if (lastLines.Count < 2) { return; } timings.SdkBuildVersion = lastLines[1]; }