From e0e73282d0628607d9a26b490e6f8ba771aaf7ad Mon Sep 17 00:00:00 2001 From: Dong-Geon Lee Date: Tue, 5 Apr 2022 02:11:20 +0900 Subject: [PATCH 1/2] Improve converting to cslist performance --- stock_indicators/_cstypes/list.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/stock_indicators/_cstypes/list.py b/stock_indicators/_cstypes/list.py index b9be7e6a..c086e7a6 100644 --- a/stock_indicators/_cstypes/list.py +++ b/stock_indicators/_cstypes/list.py @@ -1,5 +1,8 @@ +from collections import deque + from stock_indicators._cslib import CsList + class List: """ Class for converting Python's iterator type into C#'s `System.Collections.Generic.List` class. @@ -29,8 +32,7 @@ class List: """ def __new__(cls, generic, sequence) -> CsList: - clist = CsList[generic]() - for i in sequence: - clist.Add(i) - - return clist + cs_list = CsList[generic]() + deque(map(cs_list.Add, sequence), maxlen=0) + + return cs_list From 965ffe2fbc65b8fdfdb31aa4aa089dc4c2a55437 Mon Sep 17 00:00:00 2001 From: Dong-Geon Lee Date: Tue, 5 Apr 2022 02:13:06 +0900 Subject: [PATCH 2/2] Add benchmark for large nums of quotes --- benchmarks/test_benchmark_indicators.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/benchmarks/test_benchmark_indicators.py b/benchmarks/test_benchmark_indicators.py index 89a6a839..e637e446 100644 --- a/benchmarks/test_benchmark_indicators.py +++ b/benchmarks/test_benchmark_indicators.py @@ -95,6 +95,9 @@ def test_benchmark_ht_trendline(benchmark, quotes): def test_benchmark_hurst(benchmark, quotes): benchmark(indicators.get_hurst, quotes) + +def test_benchmark_hurst_longlong(benchmark, longish_quotes): + benchmark(indicators.get_hurst, longish_quotes+longish_quotes) def test_benchmark_ichimoku(benchmark, quotes): benchmark(indicators.get_ichimoku, quotes)