File: array_parsing.py

package info (click to toggle)
python-rdata 0.11.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 740 kB
  • sloc: python: 2,388; makefile: 22
file content (30 lines) | stat: -rw-r--r-- 843 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Benchmarks for array parsing time."""
import rdata
from rdata.testing import execute_r_data_source


class TimeArrayParsing:
    """
    A test for the time that it takes to parse arrays of different sizes.

    The following R code is used to create arrays of different sizes:

    ::: for (i in 1:MAX_TESTS) {
    :::     n = 2^i * 1024^2
    :::     saveRDS(
    :::         runif(n),
    :::         file=sprintf("array_%s.rds", i),
    :::         compress=FALSE,
    :::     )
    ::: }
    """
    MAX_TESTS = 5
    params = range(MAX_TESTS)

    def setup_cache(self) -> None:
        """Initialize the data."""
        execute_r_data_source(self, MAX_TESTS=self.MAX_TESTS)

    def time_array(self, i: int) -> None:
        """Test the time that it takes to parse an array."""
        rdata.parser.parse_file(f"array_{i + 1}.rds")