Skip to content

Commit

Permalink
Add benchmarks project
Browse files Browse the repository at this point in the history
  • Loading branch information
BeanCheeseBurrito committed Sep 8, 2023
1 parent 4658328 commit 48c9c87
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
51 changes: 51 additions & 0 deletions src/Flecs.NET.Benchmarks/Core/AddRemoveTag.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using BenchmarkDotNet.Attributes;
using Flecs.NET.Core;

namespace Flecs.NET.Benchmarks.Core
{
public class AddRemoveTag
{
[Params(100000)]
public int EntityCount;

[Params(1, 2, 16, 32)]
public int TagCount;

public World World;
public Entity[] Entities;
public Entity[] Tags;

[GlobalSetup]
public void Setup()
{
World = World.Create();
Entities = new Entity[EntityCount];
Tags = new Entity[TagCount];

for (int i = 0; i < EntityCount; i++)
Entities[i] = World.Entity();

for (int i = 0; i < TagCount; i++)
Tags[i] = World.Entity();
}

[GlobalCleanup]
public void Cleanup()
{
World.Dispose();
}

[Benchmark]
public void Benchmark()
{
for (int e = 0; e < EntityCount; e++)
{
for (int tag = 0; tag < TagCount; tag++)
Entities[e].Add(Tags[tag]);

for (int tag = 0; tag < TagCount; tag++)
Entities[e].Remove(Tags[tag]);
}
}
}
}
18 changes: 18 additions & 0 deletions src/Flecs.NET.Benchmarks/Flecs.NET.Benchmarks.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net6.0;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CS8618</NoWarn>
</PropertyGroup>

<Import Project="../Flecs.NET.Native/Flecs.NET.Native.targets"/>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.7"/>
<ProjectReference Include="../Flecs.NET/Flecs.NET.csproj"/>
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions src/Flecs.NET.Benchmarks/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;

[assembly: SimpleJob(runtimeMoniker: RuntimeMoniker.Net70, launchCount: 1, warmupCount: 5, iterationCount: 10)]
[assembly: SimpleJob(runtimeMoniker: RuntimeMoniker.Net60, launchCount: 1, warmupCount: 5, iterationCount: 10)]
[assembly: SimpleJob(runtimeMoniker: RuntimeMoniker.NetCoreApp31, launchCount: 1, warmupCount: 5, iterationCount: 10)]

namespace Flecs.NET.Benchmarks
{
public static class Program
{
public static void Main(string[] args)
{
BenchmarkSwitcher benchmark = BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly);
IConfig config = DefaultConfig.Instance.WithOptions(ConfigOptions.DisableOptimizationsValidator);

if (args.Length == 0)
benchmark.RunAll(config);
else
benchmark.Run(args, config);
}
}
}

0 comments on commit 48c9c87

Please sign in to comment.