Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Proposed method for git commit navigation from md file. #624

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/Tests/DotnetBenchmark/CommonFunctionsInterVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,27 @@
using AngouriMath;
using AngouriMath.Extensions;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;

namespace DotnetBenchmark
{
// DO NOT FORGET TO SWITCH TO RELEASE!
[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);
Expand Down
67 changes: 67 additions & 0 deletions Sources/Tests/DotnetBenchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using GenericTensor.Core;
using BenchmarkDotNet.Reports;
using System.Linq;
using BenchmarkDotNet.Columns;
using System.Diagnostics;

namespace DotnetBenchmark
{
Expand Down Expand Up @@ -64,6 +66,71 @@ public class NumbersBenchmark
private readonly EDecimal coef = EDecimal.FromDecimal(0.2m);
}

public class TagColumn : IColumn
{
private readonly Func<string, string> getTag;
private string? commitId = null;

public string Id { get; }

public string ColumnName { get; }

public TagColumn(string columnName, Func<string, string> 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)
Expand Down
Loading