-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
222 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,16 @@ | ||
using System.Numerics; | ||
using Arch.Core; | ||
using Arch.Core.Extensions; | ||
|
||
using Arch.Core.Utils; | ||
|
||
namespace Arch.Benchmarks; | ||
|
||
public class Benchmark | ||
{ | ||
private static void Main(string[] args) | ||
public static void Main(string[] args) | ||
{ | ||
/* | ||
// NOTE: Can this be replaced with ManualConfig.CreateEmpty()? | ||
#pragma warning disable HAA0101 // Array allocation for params parameter | ||
var config = new ManualConfig() | ||
.WithOptions(ConfigOptions.DisableOptimizationsValidator) | ||
.AddValidator(JitOptimizationsValidator.DontFailOnError) | ||
.AddLogger(ConsoleLogger.Default) | ||
.AddColumnProvider(DefaultColumnProviders.Instance); | ||
#pragma warning restore HAA0101 // Array allocation for params parameter | ||
*/ | ||
|
||
|
||
|
||
var world = World.Create(); | ||
for (var index = 0; index <= 100; index++) | ||
{ | ||
world.Create<int>(); | ||
} | ||
|
||
var desc = new QueryDescription().WithAll<int>(); | ||
for (var index = 0; index <= 100000; index++) | ||
{ | ||
world.Query(in desc, (ref int i) => | ||
{ | ||
}); | ||
} | ||
|
||
|
||
|
||
// NOTE: Is `-- --job` a typo? | ||
// Use: dotnet run -c Release --framework net7.0 -- --job short --filter *IterationBenchmark* | ||
//BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args, config); | ||
BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args); | ||
//BenchmarkSwitcher.FromAssembly(typeof(Benchmark).Assembly).Run(args, new DebugInProcessConfig()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Arch.Core; | ||
using Arch.Core.Utils; | ||
|
||
namespace Arch.Benchmarks; | ||
|
||
[HtmlExporter] | ||
//[MemoryDiagnoser] | ||
//[HardwareCounters(HardwareCounter.CacheMisses)] | ||
public class DuplicateBenchmark | ||
{ | ||
public int Amount = 100000; | ||
|
||
private static readonly ComponentType[] _group = { typeof(Transform), typeof(Velocity) }; | ||
private readonly QueryDescription _queryDescription = new(all: _group); | ||
|
||
private static World? _world; | ||
private static Entity _entity = Entity.Null; | ||
private static Entity[]? _array = null; | ||
|
||
[IterationSetup] | ||
public void Setup() | ||
{ | ||
_world = World.Create(); | ||
_world.Reserve(_group, 1); | ||
_entity = _world.Create(new Transform { X = 111, Y = 222}, new Velocity { X = 333, Y = 444 }); | ||
_array = new Entity[Amount]; | ||
} | ||
|
||
[IterationCleanup] | ||
public void Cleanup() | ||
{ | ||
World.Destroy(_world); | ||
_world = null; | ||
} | ||
|
||
/// DuplicateN() method. | ||
[Benchmark] | ||
public void DuplicateNInternal() | ||
{ | ||
_world.DuplicateN(_entity, _array.AsSpan()); | ||
} | ||
|
||
/// DuplicateN() in terms of Duplicate() method. | ||
[Benchmark] | ||
public void DuplicateNDuplicate() | ||
{ | ||
for (int i = 0; i < Amount; ++i) | ||
{ | ||
_array[i] = _world.Duplicate(_entity); | ||
} | ||
} | ||
|
||
/// Benchmark DuplicateN() if implemented via GetAllComponents. | ||
[Benchmark] | ||
public void DuplicateNGetAllComponents() | ||
{ | ||
for (int i = 0; i < Amount; ++i) | ||
{ | ||
var arch = _world.GetArchetype(_entity); | ||
var copiedEntity = _world.Create(arch.Signature); | ||
foreach (var c in _world.GetAllComponents(_entity)) | ||
{ | ||
_world.Set(_entity, c); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters