Skip to content

Commit

Permalink
Add benchmarking project for performance analysis
Browse files Browse the repository at this point in the history
Will be useful later on as we cross-compare implementations when there's new improvements

Signed-off-by: Ayane <[email protected]>
  • Loading branch information
sr229 committed Mar 25, 2024
1 parent a5636b7 commit 9ac8cc2
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 1 deletion.
8 changes: 7 additions & 1 deletion MediaPipe.NET.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediapipe.Net", "Mediapipe.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediapipe.Net.Tests", "Mediapipe.Net.Tests\Mediapipe.Net.Tests.csproj", "{3A992764-030D-4428-B2C2-F9A805E5B69A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mediapipe.Net.HelloWorld", "Mediapipe.Net.HelloWorld\Mediapipe.Net.HelloWorld.csproj", "{17D25CDE-4295-47C0-8506-E494F7E2BFA3}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mediapipe.Net.HelloWorld", "Mediapipe.Net.HelloWorld\Mediapipe.Net.HelloWorld.csproj", "{17D25CDE-4295-47C0-8506-E494F7E2BFA3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mediapipe.Net.Benchmarks", "Mediapipe.Net.Benchmarks\Mediapipe.Net.Benchmarks.csproj", "{F343EAD9-4775-4F3B-B98D-7B54A7BB3225}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -27,6 +29,10 @@ Global
{17D25CDE-4295-47C0-8506-E494F7E2BFA3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17D25CDE-4295-47C0-8506-E494F7E2BFA3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17D25CDE-4295-47C0-8506-E494F7E2BFA3}.Release|Any CPU.Build.0 = Release|Any CPU
{F343EAD9-4775-4F3B-B98D-7B54A7BB3225}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F343EAD9-4775-4F3B-B98D-7B54A7BB3225}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F343EAD9-4775-4F3B-B98D-7B54A7BB3225}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F343EAD9-4775-4F3B-B98D-7B54A7BB3225}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
49 changes: 49 additions & 0 deletions Mediapipe.Net.Benchmarks/FloatPacketPerformanceBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) homuler and The Vignette Authors
// This file is part of MediaPipe.NET.
// MediaPipe.NET is licensed under the MIT License. See LICENSE for details.

using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Running;
using Mediapipe.Net.Framework.Packets;

namespace Mediapipe.Net.Benchmarks
{
[SimpleJob(RunStrategy.ColdStart, launchCount: 50)]
[MinColumn, MaxColumn, MeanColumn, MedianColumn]
public class FloatPacketPerformanceBenchmark
{

[Benchmark]
public void InstantiateFloatPacket()
{
var randomSingle = new Random().NextSingle();
var packet = new FloatPacket(randomSingle);

packet.ValidateAsType().Ok();
}

[Benchmark]
public void InstatiateFloatArrayPacket()
{
var randomArray = new float[10];
for (var i = 0; i < randomArray.Length; i++)
{
randomArray[i] = new Random().NextSingle();
}

var packet = new FloatArrayPacket(randomArray);

packet.ValidateAsType().Ok();
}

}

public class Program
{
public static void Main(string[] args)
{
var summary = BenchmarkRunner.Run<FloatPacketPerformanceBenchmark>();
}
}
}
19 changes: 19 additions & 0 deletions Mediapipe.Net.Benchmarks/Mediapipe.Net.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.12" />
<PackageReference Include="Mediapipe.Net.Runtime.CPU" Version="0.9.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Mediapipe.Net\Mediapipe.Net.csproj" />
</ItemGroup>

</Project>

0 comments on commit 9ac8cc2

Please sign in to comment.