benchmarks

This commit is contained in:
Miha Kralj
2024-09-24 20:37:25 -07:00
parent 012458d9d7
commit 71f49e8815
4 changed files with 120 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<GenerateProgramFile>false</GenerateProgramFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.13.5" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\lib\quantalib.csproj" />
</ItemGroup>
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<Optimize>true</Optimize>
</PropertyGroup>
</Project>
+84
View File
@@ -0,0 +1,84 @@
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
namespace QuanTAlib;
public class Program
{
public static void Main(string[] args)
{
var config = DefaultConfig.Instance
.WithOption(ConfigOptions.DisableOptimizationsValidator, true);
BenchmarkRunner.Run<EmaBenchmark>(config);
}
}
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net80, launchCount: 1, warmupCount: 3, iterationCount: 5)]
public class EmaBenchmark
{
private const int Period = 10;
private const int Length = 100_000;
private GbmFeed gbm = null!;
private TSeries inputs = null!;
[GlobalSetup]
public void Setup()
{
gbm = new GbmFeed();
inputs = new();
for (int i = 0; i < Length; i++)
{
TBar item = gbm.Generate(DateTime.Now);
inputs.Add(new TValue(item.Time, item.Close, true, true));
}
}
[Benchmark]
public void Afirma_bench()
{
Afirma ma1 = new(Period);
for (int i = 0; i < Length; i++)
{
TValue item = gbm.Generate(DateTime.Now).Close;
ma1.Calc(item);
}
}
[Benchmark]
public void Alma_bench()
{
Alma ma1 = new(Period);
for (int i = 0; i < Length; i++)
{
TValue item = gbm.Generate(DateTime.Now).Close;
ma1.Calc(item);
}
}
[Benchmark]
public void Dema_bench()
{
Dema ma1 = new(Period);
for (int i = 0; i < Length; i++)
{
TValue item = gbm.Generate(DateTime.Now).Close;
ma1.Calc(item);
}
}
[Benchmark]
public void Ema_bench()
{
Ema ma1 = new(Period);
for (int i = 0; i < Length; i++)
{
TValue item = gbm.Generate(DateTime.Now).Close;
ma1.Calc(item);
}
}
}