Skip to content

Commit

Permalink
Update benchmark code and dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Apr 23, 2022
1 parent 210b39e commit 495abab
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 101 deletions.
20 changes: 1 addition & 19 deletions src/Markdig.Benchmarks/Markdig.Benchmarks.csproj
Expand Up @@ -8,29 +8,11 @@
<ItemGroup>
<None Remove="spec.md" />
</ItemGroup>
<ItemGroup>
<Reference Include="CommonMarkNew, Version=0.1.0.0, Culture=neutral, PublicKeyToken=001ef8810438905d, processorArchitecture=MSIL">
<HintPath>lib\CommonMarkNew.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Aliases>newcmark</Aliases>
<Private>True</Private>
</Reference>
<Reference Include="MoonShine">
<HintPath>lib\MoonShine.dll</HintPath>
</Reference>
<Reference Include="MarkdownDeep">
<HintPath>lib\MarkdownDeep.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Content Include="cmark.dll">
<HintPath>cmark.dll</HintPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="libsundown.dll">
<HintPath>libsundown.dll</HintPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="spec.md">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand All @@ -39,9 +21,9 @@
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.13.1" />
<PackageReference Include="CommonMark.NET" Version="0.15.1" />
<PackageReference Include="Markdown" Version="2.2.1" />
<PackageReference Include="MarkdownSharp" Version="2.0.5" />
<PackageReference Include="Microsoft.Diagnostics.Runtime" Version="2.0.226801" />
<PackageReference Include="Microsoft.Diagnostics.Tracing.TraceEvent" Version="2.0.74" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Markdig\Markdig.csproj" />
Expand Down
94 changes: 12 additions & 82 deletions src/Markdig.Benchmarks/Program.cs
@@ -1,9 +1,7 @@
// Copyright (c) Alexandre Mutel. All rights reserved.
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.
extern alias newcmark;
using System;
using System.Diagnostics;

using System.IO;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
Expand Down Expand Up @@ -55,93 +53,25 @@ public void TestCommonMarkNet()
//writer.ToString();
}

[Benchmark]
public void TestCommonMarkNetNew()
{
////var reader = new StreamReader(File.Open("spec.md", FileMode.Open));
// var reader = new StringReader(text);
//CommonMark.CommonMarkConverter.Parse(reader);
//CommonMark.CommonMarkConverter.Parse(reader);
//reader.Dispose();
//var writer = new StringWriter();
newcmark::CommonMark.CommonMarkConverter.Convert(text);
//writer.Flush();
//writer.ToString();
}

[Benchmark]
public void TestMarkdownDeep()
{
new MarkdownDeep.Markdown().Transform(text);
}

[Benchmark]
public void TestMarkdownSharp()
{
new MarkdownSharp.Markdown().Transform(text);
}

[Benchmark]
public void TestMoonshine()
{
Sundown.MoonShine.Markdownify(text);
}

static void Main(string[] args)
{
bool markdig = args.Length == 0;
bool simpleBench = false;

if (simpleBench)
{
var clock = Stopwatch.StartNew();
var program = new Program();

GC.Collect(2, GCCollectionMode.Forced, true);

var gc0 = GC.CollectionCount(0);
var gc1 = GC.CollectionCount(1);
var gc2 = GC.CollectionCount(2);

const int count = 12*64;
for (int i = 0; i < count; i++)
{
if (markdig)
{
program.TestMarkdig();
}
else
{
program.TestCommonMarkNetNew();
}
}
clock.Stop();
Console.WriteLine((markdig ? "MarkDig" : "CommonMark") + $" => time: {(double)clock.ElapsedMilliseconds/count}ms (total {clock.ElapsedMilliseconds}ms)");
DumpGC(gc0, gc1, gc2);
}
else
{
//new TestMatchPerf().TestMatch();

var config = ManualConfig.Create(DefaultConfig.Instance);
//var gcDiagnoser = new MemoryDiagnoser();
//config.Add(new Job { Mode = Mode.SingleRun, LaunchCount = 2, WarmupCount = 2, IterationTime = 1024, TargetCount = 10 });
//config.Add(new Job { Mode = Mode.Throughput, LaunchCount = 2, WarmupCount = 2, TargetCount = 10 });
//config.Add(gcDiagnoser);

//var config = DefaultConfig.Instance;
BenchmarkRunner.Run<Program>(config);
//BenchmarkRunner.Run<TestDictionary>(config);
//BenchmarkRunner.Run<TestMatchPerf>();
//BenchmarkRunner.Run<TestStringPerf>();
}
}

private static void DumpGC(int gc0, int gc1, int gc2)
{
Console.WriteLine($"gc0: {GC.CollectionCount(0)-gc0}");
Console.WriteLine($"gc1: {GC.CollectionCount(1)-gc1}");
Console.WriteLine($"gc2: {GC.CollectionCount(2)-gc2}");
var config = ManualConfig.Create(DefaultConfig.Instance);
//var gcDiagnoser = new MemoryDiagnoser();
//config.Add(new Job { Mode = Mode.SingleRun, LaunchCount = 2, WarmupCount = 2, IterationTime = 1024, TargetCount = 10 });
//config.Add(new Job { Mode = Mode.Throughput, LaunchCount = 2, WarmupCount = 2, TargetCount = 10 });
//config.Add(gcDiagnoser);

//var config = DefaultConfig.Instance;
BenchmarkRunner.Run<Program>(config);
//BenchmarkRunner.Run<TestDictionary>(config);
//BenchmarkRunner.Run<TestMatchPerf>();
//BenchmarkRunner.Run<TestStringPerf>();
}
}
}
Binary file modified src/Markdig.Benchmarks/cmark.dll
Binary file not shown.
Binary file removed src/Markdig.Benchmarks/lib/CommonMarkNew.dll
Binary file not shown.
Binary file removed src/Markdig.Benchmarks/lib/MarkdownDeep.dll
Binary file not shown.
Binary file removed src/Markdig.Benchmarks/lib/MoonShine.dll
Binary file not shown.
Binary file removed src/Markdig.Benchmarks/libsundown.dll
Binary file not shown.

0 comments on commit 495abab

Please sign in to comment.