From 30a86634dba8903d03028c3d6a8325ee630f3b14 Mon Sep 17 00:00:00 2001 From: dasingh92 Date: Mon, 15 Jan 2024 10:20:32 +1100 Subject: [PATCH] [WIP] Proposed method for git commit navigation from md file. --- .../CommonFunctionsInterVersion.cs | 11 +++ Sources/Tests/DotnetBenchmark/Program.cs | 67 +++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/Sources/Tests/DotnetBenchmark/CommonFunctionsInterVersion.cs b/Sources/Tests/DotnetBenchmark/CommonFunctionsInterVersion.cs index 05ad33c33..687ee2a48 100644 --- a/Sources/Tests/DotnetBenchmark/CommonFunctionsInterVersion.cs +++ b/Sources/Tests/DotnetBenchmark/CommonFunctionsInterVersion.cs @@ -10,7 +10,9 @@ using AngouriMath; using AngouriMath.Extensions; using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; using BenchmarkDotNet.Exporters.Csv; +using BenchmarkDotNet.Jobs; namespace DotnetBenchmark { @@ -18,8 +20,17 @@ namespace DotnetBenchmark [ArtifactsPath(@"./benchmark_results.csv")] [CsvExporter(CsvSeparator.Semicolon)] [MemoryDiagnoser] + [Config(typeof(Config))] public class CommonFunctionsInterVersion { + private class Config : ManualConfig + { + public Config() + { + AddColumn(new TagColumn("CommitId", name => name)); + } + } + // Testing parsing [Benchmark] public void ParseEasy() => MathS.FromString("1 + 2 / x + 2 / (y + x)", useCache: false); [Benchmark] public void ParseHard() => MathS.FromString("x ^ (x + y ^ 2 ^ sin(3 / z + i)) - log(-i, 3) ^ (x + x * y) - sqrt(y) / (i + sqrt(-1))", useCache: false); diff --git a/Sources/Tests/DotnetBenchmark/Program.cs b/Sources/Tests/DotnetBenchmark/Program.cs index c59d0b0e4..1c48b0dad 100644 --- a/Sources/Tests/DotnetBenchmark/Program.cs +++ b/Sources/Tests/DotnetBenchmark/Program.cs @@ -17,6 +17,8 @@ using GenericTensor.Core; using BenchmarkDotNet.Reports; using System.Linq; +using BenchmarkDotNet.Columns; +using System.Diagnostics; namespace DotnetBenchmark { @@ -64,6 +66,71 @@ public class NumbersBenchmark private readonly EDecimal coef = EDecimal.FromDecimal(0.2m); } + public class TagColumn : IColumn + { + private readonly Func getTag; + private string? commitId = null; + + public string Id { get; } + + public string ColumnName { get; } + + public TagColumn(string columnName, Func getTag) + { + this.getTag = getTag; + ColumnName = columnName; + Id = nameof(TagColumn) + "_" + ColumnName; + } + + public bool AlwaysShow => true; + + public ColumnCategory Category => ColumnCategory.Custom; + + public int PriorityInCategory => 0; + + public bool IsNumeric => false; + + public UnitType UnitType => UnitType.Dimensionless; + + public string Legend => $"Custom {ColumnName} tag column"; + + public string GetValue(Summary summary, BenchmarkCase benchmarkCase) => getTag(GetGitCommitId()); + + private string GetGitCommitId() + { + if (commitId != null) + return commitId; + try + { + Process cmdGit = new Process(); + cmdGit.StartInfo.FileName = "C:\\Program Files\\Git\\cmd\\git.exe"; + cmdGit.StartInfo.RedirectStandardInput = true; + cmdGit.StartInfo.RedirectStandardOutput = true; + cmdGit.StartInfo.CreateNoWindow = true; + cmdGit.StartInfo.UseShellExecute = false; + cmdGit.StartInfo.Arguments = "rev-parse HEAD --short"; + cmdGit.Start(); + cmdGit.WaitForExit(1000); + commitId = cmdGit.StandardOutput.ReadToEnd(); + // this commitId can be used for direct navigation to the commit as below: + // https://github.com/asc-community/AngouriMath/commit/{commitId} + } + catch + { + Console.Error.WriteLine("Couldn't fetch git commit id"); + commitId = string.Empty; + + } + return commitId; + } + + public string GetValue(Summary summary, BenchmarkCase benchmarkCase, SummaryStyle style) => GetValue(summary, benchmarkCase); + + public bool IsAvailable(Summary summary) => true; + + public bool IsDefault(Summary summary, BenchmarkCase benchmarkCase) => false; + } + public class Program { public static void Main(string[] args)