|
| 1 | +""" |
| 2 | +Copyright 2025 Man Group Operations Limited |
| 3 | +
|
| 4 | +Use of this software is governed by the Business Source License 1.1 included in the file licenses/BSL.txt. |
| 5 | +
|
| 6 | +As of the Change Date specified in that file, in accordance with the Business Source License, use of this software will be governed by the Apache License, version 2.0. |
| 7 | +""" |
| 8 | + |
| 9 | + |
| 10 | +import numpy as np |
| 11 | +import pandas as pd |
| 12 | + |
| 13 | +from arcticdb import Arctic, OutputFormat |
| 14 | +from arcticdb.util.test import random_strings_of_length |
| 15 | + |
| 16 | + |
| 17 | +class ArrowReadNumeric: |
| 18 | + number = 5 |
| 19 | + warmup_time = 0 |
| 20 | + timeout = 6000 |
| 21 | + rounds = 1 |
| 22 | + connection_string = "lmdb://arrow_read_numeric?map_size=20GB" |
| 23 | + lib_name = "arrow_read_numeric" |
| 24 | + params = ([100_000, 100_000_000], [None, "middle"]) |
| 25 | + param_names = ["rows", "date_range"] |
| 26 | + |
| 27 | + def symbol_name(self, num_rows: int): |
| 28 | + return f"numeric_{num_rows}_rows" |
| 29 | + |
| 30 | + def setup_cache(self): |
| 31 | + self.ac = Arctic(self.connection_string, output_format=OutputFormat.EXPERIMENTAL_ARROW) |
| 32 | + num_rows, date_ranges = self.params |
| 33 | + num_cols = 9 # 10 including the index column |
| 34 | + self.ac.delete_library(self.lib_name) |
| 35 | + self.ac.create_library(self.lib_name) |
| 36 | + lib = self.ac.get_library(self.lib_name) |
| 37 | + for rows in num_rows: |
| 38 | + df = pd.DataFrame( |
| 39 | + { |
| 40 | + f"col{idx}": np.arange(idx * rows, (idx + 1) * rows, dtype=np.int64) for idx in range(num_cols) |
| 41 | + }, |
| 42 | + index = pd.date_range("1970-01-01", freq="ns", periods=rows) |
| 43 | + ) |
| 44 | + lib.write(self.symbol_name(rows), df) |
| 45 | + |
| 46 | + def teardown(self, rows, date_range): |
| 47 | + del self.ac |
| 48 | + |
| 49 | + def setup(self, rows, date_range): |
| 50 | + self.ac = Arctic(self.connection_string, output_format=OutputFormat.EXPERIMENTAL_ARROW) |
| 51 | + self.lib = self.ac.get_library(self.lib_name) |
| 52 | + if date_range is None: |
| 53 | + self.date_range = None |
| 54 | + else: |
| 55 | + # Create a date range that excludes the first and last 10 rows of the data only |
| 56 | + self.date_range = (pd.Timestamp(10), pd.Timestamp(rows - 10)) |
| 57 | + |
| 58 | + def time_read(self, rows, date_range): |
| 59 | + self.lib.read(self.symbol_name(rows), date_range=self.date_range) |
| 60 | + |
| 61 | + def peakmem_read(self, rows, date_range): |
| 62 | + self.lib.read(self.symbol_name(rows), date_range=self.date_range) |
| 63 | + |
| 64 | + |
| 65 | +class ArrowReadStrings: |
| 66 | + number = 5 |
| 67 | + warmup_time = 0 |
| 68 | + timeout = 6000 |
| 69 | + rounds = 1 |
| 70 | + connection_string = "lmdb://arrow_read_strings?map_size=20GB" |
| 71 | + lib_name = "arrow_read_strings" |
| 72 | + params = ([10_000, 1_000_000], [None, "middle"], [1, 100, 100_000]) |
| 73 | + param_names = ["rows", "date_range", "unique_string_count"] |
| 74 | + |
| 75 | + def symbol_name(self, num_rows: int, unique_strings: int): |
| 76 | + return f"string_{num_rows}_rows_{unique_strings}_unique_strings" |
| 77 | + |
| 78 | + def setup_cache(self): |
| 79 | + rng = np.random.default_rng() |
| 80 | + self.ac = Arctic(self.connection_string, output_format=OutputFormat.EXPERIMENTAL_ARROW) |
| 81 | + num_rows, date_ranges, unique_string_counts = self.params |
| 82 | + num_cols = 10 |
| 83 | + self.ac.delete_library(self.lib_name) |
| 84 | + self.ac.create_library(self.lib_name) |
| 85 | + lib = self.ac.get_library(self.lib_name) |
| 86 | + for unique_string_count in unique_string_counts: |
| 87 | + strings = np.array(random_strings_of_length(unique_string_count, 10, unique=True)) |
| 88 | + for rows in num_rows: |
| 89 | + df = pd.DataFrame( |
| 90 | + { |
| 91 | + f"col{idx}": rng.choice(strings, rows) for idx in range(num_cols) |
| 92 | + }, |
| 93 | + index = pd.date_range("1970-01-01", freq="ns", periods=rows) |
| 94 | + ) |
| 95 | + lib.write(self.symbol_name(rows, unique_string_count), df) |
| 96 | + |
| 97 | + def teardown(self, rows, date_range, unique_string_count): |
| 98 | + del self.ac |
| 99 | + |
| 100 | + def setup(self, rows, date_range, unique_string_count): |
| 101 | + self.ac = Arctic(self.connection_string, output_format=OutputFormat.EXPERIMENTAL_ARROW) |
| 102 | + self.lib = self.ac.get_library(self.lib_name) |
| 103 | + if date_range is None: |
| 104 | + self.date_range = None |
| 105 | + else: |
| 106 | + # Create a date range that excludes the first and last 10 rows of the data only |
| 107 | + self.date_range = (pd.Timestamp(10), pd.Timestamp(rows - 10)) |
| 108 | + |
| 109 | + def time_read(self, rows, date_range, unique_string_count): |
| 110 | + self.lib.read(self.symbol_name(rows, unique_string_count), date_range=self.date_range) |
| 111 | + |
| 112 | + def peakmem_read(self, rows, date_range, unique_string_count): |
| 113 | + self.lib.read(self.symbol_name(rows, unique_string_count), date_range=self.date_range) |
0 commit comments