Skip to content

Commit

Permalink
add AdxAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Nov 9, 2023
1 parent ca10bc9 commit 42d4d7f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/a-d/Adx/Adx.Api.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ public static IEnumerable<AdxResult> GetAdx<TQuote>(
where TQuote : IQuote => quotes
.ToQuoteD()
.CalcAdx(lookbackPeriods);

// TASK, from TQuote
/// <include file='./info.xml' path='info/*' />
///
public static Task<IEnumerable<AdxResult>> GetAdxAsync<TQuote>(
this IEnumerable<TQuote> quotes,
int lookbackPeriods = 14)
where TQuote : IQuote => Task.Run(() => quotes
.GetAdx(lookbackPeriods));
}
25 changes: 25 additions & 0 deletions tests/indicators/a-d/Adx/Adx.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ public void Standard()
Assert.AreEqual(34.2987, r501.Adx.Round(4));
}

[TestMethod]
public async Task Async()
{
List<AdxResult> ogList = quotes
.GetAdx(14)
.ToList();

IEnumerable<AdxResult> results = await quotes
.GetAdxAsync(14)
.ConfigureAwait(false);

List<AdxResult> rsList = results.ToList();

Assert.AreEqual(ogList.Count, rsList.Count);

for (int i = 0; i < rsList.Count; i++)
{
AdxResult o = ogList[i];
AdxResult r = rsList[i];

Assert.AreEqual(o.Date, r.Date);
Assert.AreEqual(o.Adx, r.Adx);
}
}

[TestMethod]
public void Chainor()
{
Expand Down
25 changes: 25 additions & 0 deletions tests/performance/Perf.Indicators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ public static void SetupCompare()
[Benchmark]
public object GetAdx() => h.GetAdx();

[Benchmark]
public async Task<object> GetAdxAsync()
=> await h.GetAdxAsync()
.ConfigureAwait(false);

[Benchmark]
public async Task<object> GetAdxAsyncExtension()
=> await h.GetAdx()
.AsAsync()
.ConfigureAwait(false);

[Benchmark]
public async Task<object> GetAdx3asyncExt()
{
Task<IEnumerable<AdxResult>> taskA = h.GetAdx(13).AsAsync();
Task<IEnumerable<AdxResult>> taskB = h.GetAdx(14).AsAsync();
Task<IEnumerable<AdxResult>> taskC = h.GetAdx(15).AsAsync();

await taskA.ConfigureAwait(false);
await taskB.ConfigureAwait(false);
await taskC.ConfigureAwait(false);

return "foo";
}

[Benchmark]
public object GetAlligator() => h.GetAlligator();

Expand Down

0 comments on commit 42d4d7f

Please sign in to comment.