Skip to content

Commit

Permalink
Update benchmarking due to recent refactoring in TALib
Browse files Browse the repository at this point in the history
  • Loading branch information
hmG3 committed Mar 14, 2024
1 parent 4fd99c2 commit d0f2c76
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
47 changes: 19 additions & 28 deletions src/TaTooIne.Benchmark/IndicatorsBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public void TulipIterationSetup()
_tulipPeriodOption++;

var currentIndicator =
(Indicator) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(this)!;
(Indicator) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentIndicatorIndex =
(int) GetType().GetField("__argField1", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentIndicatorOptions = _tulipOptions[currentIndicatorIndex];
Expand Down Expand Up @@ -106,8 +105,7 @@ public void Tulip(Indicator Indicator, int order)
}
}

public static IEnumerable<object[]> TulipSource() =>
Indicators.All.Select((indicator, index) => new object[] { indicator, index });
public static IEnumerable<object[]> TulipSource() => Indicators.All.Select((indicator, index) => new object[] { indicator, index });

[GlobalCleanup(Target = "Tulip")]
public void GlobalTulipCleanup() => _inputsMemoryPool.Dispose();
Expand All @@ -126,8 +124,7 @@ public void TALibIterationSetup()
_talibPeriodOption++;

var currentFunction =
(Function) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!
.GetValue(this)!;
(Function) GetType().GetField("__argField0", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentFunctionIndex =
(int) GetType().GetField("__argField1", BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(this)!;
var currentFunctionOptions = _talibOptions[currentFunctionIndex];
Expand Down Expand Up @@ -207,8 +204,7 @@ public void TALib(Function Indicator, int order)
}
}

public static IEnumerable<object[]> TALibSource() =>
Functions.All.Select((function, index) => new object[] { function, index });
public static IEnumerable<object[]> TALibSource() => Abstract.All.Select((function, index) => new object[] { function, index });

[GlobalCleanup(Target = "TALib")]
public void GlobalTALibCleanup() => _inputsMemoryPool.Dispose();
Expand Down Expand Up @@ -309,42 +305,36 @@ private void SetupTALib()
Near = 0.3
};

Core.SetCandleSettings(
Core.CandleSettingType.BodyDoji, Core.RangeType.HighLow, candleDefaultConfig.Period,
candleDefaultConfig.BodyNone);
Core.CandleSettings.Set(Core.CandleSettingType.BodyDoji,
new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.BodyNone));

Core.SetCandleSettings(
Core.CandleSettingType.BodyShort, Core.RangeType.RealBody, candleDefaultConfig.Period,
candleDefaultConfig.BodyShort);
Core.CandleSettings.Set(Core.CandleSettingType.BodyShort,
new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.BodyShort));

Core.SetCandleSettings(
Core.CandleSettingType.BodyLong, Core.RangeType.RealBody, candleDefaultConfig.Period,
candleDefaultConfig.BodyLong);
Core.CandleSettings.Set(Core.CandleSettingType.BodyLong,
new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.BodyLong));

Core.SetCandleSettings(
Core.CandleSettingType.ShadowVeryShort, Core.RangeType.HighLow, candleDefaultConfig.Period,
candleDefaultConfig.WickNone);
Core.CandleSettings.Set(Core.CandleSettingType.ShadowVeryShort,
new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.WickNone));

Core.SetCandleSettings(
Core.CandleSettingType.ShadowLong, Core.RangeType.RealBody, candleDefaultConfig.Period,
candleDefaultConfig.WickLong);
Core.CandleSettings.Set(Core.CandleSettingType.ShadowLong,
new Core.CandleSetting(Core.CandleRangeType.RealBody, candleDefaultConfig.Period, candleDefaultConfig.WickLong));

Core.SetCandleSettings(
Core.CandleSettingType.Near, Core.RangeType.HighLow, candleDefaultConfig.Period,
candleDefaultConfig.Near);
Core.CandleSettings.Set(Core.CandleSettingType.Near,
new Core.CandleSetting(Core.CandleRangeType.HighLow, candleDefaultConfig.Period, candleDefaultConfig.Near));
}

private void SetupTALibInputs()
{
var functionsCount = Functions.All.Count();
var functionsCount = Abstract.All.Count();

_talibInputs = new Dictionary<int, double[][]>(functionsCount);
_talibOptions = new Dictionary<int, double[]>(functionsCount);
_talibOutputs = new Dictionary<int, double[][]>(functionsCount);

for (var i = 0; i < functionsCount; i++)
{
var function = Functions.All.ElementAt(i);
var function = Abstract.All.ElementAt(i);

var (inputs, options, outputs) = PrepareParams(function);
_talibInputs.Add(i, inputs);
Expand Down Expand Up @@ -419,6 +409,7 @@ private void SetupTALibInputs()
{
inputData[i] = random.Next(30);
}

inputs[j] = inputData;
break;
}
Expand Down
13 changes: 11 additions & 2 deletions src/TaTooIne.Benchmark/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Globalization;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Reports;
Expand All @@ -14,11 +16,18 @@
.AddDiagnoser(MemoryDiagnoser.Default)
.AddLogicalGroupRules(BenchmarkLogicalGroupRule.ByParams)
.WithOrderer(BenchmarkOrderer.Instance)
.WithSummaryStyle(SummaryStyle.Default.WithTimeUnit(TimeUnit.Millisecond))
.WithSummaryStyle(new SummaryStyle(
cultureInfo: CultureInfo.CurrentCulture,
printUnitsInHeader: true,
printUnitsInContent: false,
timeUnit: TimeUnit.Millisecond,
sizeUnit: SizeUnit.KB
))
.WithUnionRule(ConfigUnionRule.Union);
#if DEBUG
config = ManualConfig.Union(new DebugInProcessConfig(), config);
#else

config = ManualConfig.Union(config, ManualConfig.CreateEmpty()
.AddLogger(ConsoleLogger.Default)
.AddJob(Job.Default.WithRuntime(CoreRuntime.Core80))
Expand All @@ -29,7 +38,7 @@
BenchmarkParamsColumnProvider.Instance,
DefaultColumnProviders.Metrics
])
.AddExporter(HtmlExporter.Default));
.AddExporter(HtmlExporter.Default, CsvExporter.Default, MarkdownExporter.Console));
#endif

BenchmarkRunner.Run<IndicatorsBenchmark>(config);

0 comments on commit d0f2c76

Please sign in to comment.