Add benchmarks
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Craftimizer.Benchmark;
|
||||
|
||||
[SimpleJob(RuntimeMoniker.Net70)]
|
||||
[SimpleJob(RuntimeMoniker.NativeAot70)]
|
||||
public class Bench
|
||||
{
|
||||
private float[] data;
|
||||
private int[] dataLengths;
|
||||
|
||||
[Params(1000, 10000)]
|
||||
public int N;
|
||||
|
||||
[GlobalSetup]
|
||||
public void Setup()
|
||||
{
|
||||
var rand = new Random();
|
||||
data = new float[N * 8];
|
||||
dataLengths = new int[N];
|
||||
for (var i = 0; i < data.Length; i += 8)
|
||||
{
|
||||
var len = rand.NextSingle() > .5 ? 8 : rand.Next(1, 9);
|
||||
dataLengths[i / 8] = len;
|
||||
for (var j = 0; j < len; ++j)
|
||||
data[i + j] = rand.NextSingle();
|
||||
for (var j = len; j < 8; ++j)
|
||||
data[i + j] = float.NaN;
|
||||
}
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int[] Scalar()
|
||||
{
|
||||
var d = new int[N];
|
||||
var dataSpan = data.AsSpan();
|
||||
for (var i = 0; i < N; ++i)
|
||||
d[i] = Solver.Crafty.Solver.HMaxIndexScalar(new Vector<float>(dataSpan.Slice(i * 8, 8)), dataLengths[i]);
|
||||
return d;
|
||||
}
|
||||
|
||||
[Benchmark]
|
||||
public int[] AVX2()
|
||||
{
|
||||
var d = new int[128];
|
||||
var dataSpan = data.AsSpan();
|
||||
for (var i = 0; i < 128; ++i)
|
||||
d[i] = Solver.Crafty.Solver.HMaxIndexAVX2(new Vector<float>(dataSpan.Slice(i * 8, 8)), dataLengths[i]);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
|
||||
<PackageReference Include="Meziantou.Analyzer" Version="2.0.61">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using BenchmarkDotNet.Running;
|
||||
using Craftimizer.Simulator;
|
||||
using Craftimizer.Simulator.Actions;
|
||||
using Craftimizer.Solver.Crafty;
|
||||
@@ -10,6 +11,9 @@ internal static class Program
|
||||
{
|
||||
private static void Main()
|
||||
{
|
||||
//var summary = BenchmarkRunner.Run<Bench>();
|
||||
//return;
|
||||
|
||||
//TypeLayout.PrintLayout<ArenaNode<SimulationNode>>(true);
|
||||
//return;
|
||||
|
||||
@@ -33,7 +37,7 @@ internal static class Program
|
||||
|
||||
var config = new SolverConfig()
|
||||
{
|
||||
Iterations = 1_000_000
|
||||
Iterations = 30_000,//1_000_000
|
||||
};
|
||||
|
||||
var s = Stopwatch.StartNew();
|
||||
|
||||
Reference in New Issue
Block a user