From 71f49e88155d2934893fbd922d1b2082b6238843 Mon Sep 17 00:00:00 2001 From: Miha Kralj Date: Tue, 24 Sep 2024 20:37:25 -0700 Subject: [PATCH] benchmarks --- QuanTAlib.sln | 9 +++- benchmark/benchmark.csproj | 28 ++++++++++++ benchmark/growthBench.cs | 84 +++++++++++++++++++++++++++++++++++ docs/indicators/indicators.md | 2 +- 4 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 benchmark/benchmark.csproj create mode 100644 benchmark/growthBench.cs diff --git a/QuanTAlib.sln b/QuanTAlib.sln index a6ac4ee3..7b1d3247 100644 --- a/QuanTAlib.sln +++ b/QuanTAlib.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31903.59 @@ -15,6 +15,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "quantower", "quantower", "{ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Statistics", "quantower\Statistics\Statistics.csproj", "{B6D3EB11-63B6-430F-B526-E1981B3D8214}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "benchmark", "benchmark\benchmark.csproj", "{6629C6D2-FC34-4BDF-AEF4-A5859E05981E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -44,9 +46,12 @@ Global {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Debug|Any CPU.Build.0 = Debug|Any CPU {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Release|Any CPU.ActiveCfg = Release|Any CPU {B6D3EB11-63B6-430F-B526-E1981B3D8214}.Release|Any CPU.Build.0 = Release|Any CPU + {6629C6D2-FC34-4BDF-AEF4-A5859E05981E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6629C6D2-FC34-4BDF-AEF4-A5859E05981E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6629C6D2-FC34-4BDF-AEF4-A5859E05981E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6629C6D2-FC34-4BDF-AEF4-A5859E05981E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {B6D3EB11-63B6-430F-B526-E1981B3D8214} = {A8D9AE68-24E3-476C-BB98-244541BB4B43} EndGlobalSection EndGlobal - diff --git a/benchmark/benchmark.csproj b/benchmark/benchmark.csproj new file mode 100644 index 00000000..0940953e --- /dev/null +++ b/benchmark/benchmark.csproj @@ -0,0 +1,28 @@ + + + + Exe + net8.0 + false + enable + latest + false + + + + + + + + + + + + true + AnyCPU + pdbonly + true + true + + + \ No newline at end of file diff --git a/benchmark/growthBench.cs b/benchmark/growthBench.cs new file mode 100644 index 00000000..c01cdd8f --- /dev/null +++ b/benchmark/growthBench.cs @@ -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(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); + } + } +} \ No newline at end of file diff --git a/docs/indicators/indicators.md b/docs/indicators/indicators.md index 8de0cd95..e26a8a65 100644 --- a/docs/indicators/indicators.md +++ b/docs/indicators/indicators.md @@ -14,7 +14,7 @@ |HLCC4 - Weighted Price|`️.HLCC4`||`WclPrice`|| |
|||| |**AVERAGES & TRENDS**|**QuanTALib**|Skender.Stock|TALib.NETCore|Tulip.NETCore|Trady| -|AFIRMA - Autoregressive Finite Impulse Response Moving Average|`✔️`|||| +|AFIRMA - Autoregressive Finite Impulse Response Moving Average|`Afirma`|||| |ALMA - Arnaud Legoux Moving Average|`Alma`|`✔️`||| |⭐DEMA - Double EMA Average|`Dema`|`⭐`|`⭐`|`⭐`|| |DSMA - Deviation Scaled Moving Average|`Dsma`||||