diff --git a/benchmarks/conftest.py b/benchmarks/conftest.py index 377b95c5..28aaf09e 100644 --- a/benchmarks/conftest.py +++ b/benchmarks/conftest.py @@ -1,15 +1,12 @@ import csv import logging -import os -import platform from datetime import datetime from decimal import Decimal, DecimalException from pathlib import Path import pytest -from stock_indicators._cslib import clr -from stock_indicators.indicators.common import Quote # pre-initialized +from stock_indicators.indicators.common import Quote from stock_indicators.logging_config import configure_logging @@ -64,6 +61,10 @@ def parse_date(date_str): return datetime.now() +@pytest.fixture(scope="session") +def raw_data(filename: str = 'Default'): + return get_data_from_csv(filename) + @pytest.fixture(scope="session") def quotes(days: int = 502): rows = get_data_from_csv("Default") diff --git a/benchmarks/test_benchmark_indicators.py b/benchmarks/test_benchmark_indicators.py index d5585b78..32459dd8 100644 --- a/benchmarks/test_benchmark_indicators.py +++ b/benchmarks/test_benchmark_indicators.py @@ -252,3 +252,26 @@ def test_benchmark_wma(self, benchmark, quotes): def test_benchmark_zig_zag(self, benchmark, quotes): benchmark(indicators.get_zig_zag, quotes) + + def test_benchmark_converting_to_IndicatorResults(self, benchmark, quotes): + from stock_indicators._cslib import CsIndicator + from stock_indicators.indicators.common.enums import CandlePart + from stock_indicators.indicators.common.quote import Quote + from stock_indicators.indicators.sma import SMAResults, SMAResult + + candle_part: CandlePart = CandlePart.CLOSE + lookback_periods = 12 + quotes = Quote.use(quotes * 1000, candle_part) # Error occurs if not assigned to local var. + results = CsIndicator.GetSma(quotes, lookback_periods) + + benchmark(SMAResults, results, SMAResult) + + def test_benchmark_converting_to_CsDecimal(self, benchmark, raw_data): + from stock_indicators._cstypes import Decimal as CsDecimal + raw_data = raw_data * 1000 + + def convert_to_quotes(rows): + for row in rows: + CsDecimal(row[2]) + + benchmark(convert_to_quotes, raw_data) \ No newline at end of file