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

Added Unity mono benchmark #14

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion samples/BinaryPack.Benchmark/BinaryPack.Benchmark.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
<PackageReference Include="BenchmarkDotNet" Version="0.13.7" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to update the version in the R script

<PackageReference Include="BinaryPack" Version="1.0.3" Condition="'$(TargetFramework)' == 'net7'" />
<PackageReference Include="IsExternalInit" Version="1.0.3" Condition="'$(TargetFramework)' == 'net472'" />
<PackageReference Include="MessagePack" Version="2.3.85" />
Expand Down
2 changes: 2 additions & 0 deletions samples/BinaryPack.Benchmark/Implementation/Benchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;
using BinaryPack.Benchmark.Jobs;
using BinaryPack.Models.Interfaces;
using JsonTextWriter = Newtonsoft.Json.JsonTextWriter;
using JsonTextReader = Newtonsoft.Json.JsonTextReader;
Expand All @@ -20,6 +21,7 @@ namespace BinaryPack.Benchmark.Implementation
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net472, id: "NET_472")]
[SimpleJob(RuntimeMoniker.Net70, id:"NET_7")]
[UnityJob("2019.4.36f1")]
[CategoriesColumn]
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
public partial class Benchmark<T> where T : class, IInitializable, IEquatable<T>, new()
Expand Down
56 changes: 56 additions & 0 deletions samples/BinaryPack.Benchmark/Jobs/UnityJobAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.IO;
using System.Runtime.InteropServices;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Loggers;
using Microsoft.Win32;

namespace BinaryPack.Benchmark.Jobs;

[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class, AllowMultiple = true)]
public class UnityJobAttribute : MonoJobAttribute
{
public UnityJobAttribute(string version)
: base($"Unity {version}", GetUnityMonoExeFromVersion(version))
{
}

private static string GetUnityMonoExeFromVersion(string version)
{
static void LogUnityNotOnMachine(string version)
{
ConsoleLogger.Default.WriteLineError($"Unity {version} was not found on this machine.");
}

// TODO: Support job on Mac/Linux platforms.
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
ConsoleLogger.Default.WriteLineError("Unity jobs are not yet supported on operating systems other than Windows.");
return "";
}
string? unityPath;
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64))
using (RegistryKey? unityInstaller = baseKey.OpenSubKey($@"SOFTWARE\Unity Technologies\Installer\Unity {version}"))
{
if (unityInstaller == null)
{
LogUnityNotOnMachine(version);
return "";
}
unityPath = unityInstaller.GetValue("Location x64")?.ToString();
if (unityPath == null)
{
LogUnityNotOnMachine(version);
return "";
}
}
string unityMonoExe = @$"{unityPath}\Editor\Data\MonoBleedingEdge\bin\mono.exe";
if (!File.Exists(unityMonoExe))
{
LogUnityNotOnMachine(version);
return "";
}

return unityMonoExe;
}
}
18 changes: 6 additions & 12 deletions samples/BinaryPack.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
using BinaryPack.Benchmark.Implementation;
using BinaryPack.Models;

namespace BinaryPack.Benchmark
namespace BinaryPack.Benchmark;

public class Program
{
public class Program
public static void Main()
{
public static void Main()
{
/* =================
* BenchmarkDotNet
* ================
* In order to run this benchmark, compile this project in Release mode,
* then go to its bin\Release\net* folder, open a cmd prompt
* and type "dotnet BinaryPack.Benchmark.dll */
BenchmarkRunner.Run<Benchmark<JsonResponseModel>>();
}
// Run via CLI: dotnet run --project BinaryPack.Benchmark.csproj -c Release --framework net472
BenchmarkRunner.Run<Benchmark<JsonResponseModel>>();
}
}