mirror of
https://github.com/cosyneco/MediaPipe.NET.git
synced 2025-07-04 12:17:14 +08:00
Add benchmarking project for performance analysis
Will be useful later on as we cross-compare implementations when there's new improvements Signed-off-by: Ayane <ayane@vignetteapp.org>
This commit is contained in:
@ -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
|
||||
@ -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
|
||||
|
49
Mediapipe.Net.Benchmarks/FloatPacketPerformanceBenchmark.cs
Normal file
49
Mediapipe.Net.Benchmarks/FloatPacketPerformanceBenchmark.cs
Normal file
@ -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
Mediapipe.Net.Benchmarks/Mediapipe.Net.Benchmarks.csproj
Normal file
19
Mediapipe.Net.Benchmarks/Mediapipe.Net.Benchmarks.csproj
Normal file
@ -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>
|
Reference in New Issue
Block a user