Skip to content

Commit f62b0ca

Browse files
authored
benchmarks: Add a read all available benchmark (#883)
* benchmarks: Add a read_all_available benchmark * chore: Fix formatting
1 parent da2233f commit f62b0ca

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

tests/benchmark/test_analog_stream_readers.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pytest_benchmark.fixture import BenchmarkFixture
99

1010
from nidaqmx import Task
11-
from nidaqmx.constants import WaveformAttributeMode
11+
from nidaqmx.constants import READ_ALL_AVAILABLE, WaveformAttributeMode
1212
from nidaqmx.stream_readers._analog_multi_channel_reader import AnalogMultiChannelReader
1313
from nidaqmx.stream_readers._analog_single_channel_reader import (
1414
AnalogSingleChannelReader,
@@ -39,6 +39,18 @@ def test___analog_single_channel_reader___read_many_sample(
3939
benchmark(reader.read_many_sample, data, num_samples)
4040

4141

42+
@pytest.mark.benchmark(group="analog_readers")
43+
@pytest.mark.parametrize("num_samples", [1, 1000])
44+
def test___analog_single_channel_reader___read_all_available(
45+
benchmark: BenchmarkFixture, ai_benchmark_task: Task, num_samples: int
46+
) -> None:
47+
reader = AnalogSingleChannelReader(ai_benchmark_task.in_stream)
48+
# This test reads the whole buffer, which is 2x num_samples.
49+
data = numpy.full(num_samples * 2, math.inf, dtype=numpy.float64)
50+
51+
benchmark(reader.read_many_sample, data, READ_ALL_AVAILABLE)
52+
53+
4254
@pytest.mark.benchmark(group="analog_readers")
4355
@pytest.mark.parametrize("num_samples", [1, 1000])
4456
@pytest.mark.parametrize(
@@ -81,6 +93,19 @@ def test___analog_multi_channel_reader___read_many_sample(
8193
benchmark(reader.read_many_sample, data, num_samples)
8294

8395

96+
@pytest.mark.benchmark(group="analog_readers")
97+
@pytest.mark.parametrize("num_channels", [1, 2, 8])
98+
@pytest.mark.parametrize("num_samples", [1, 1000])
99+
def test___analog_multi_channel_reader___read_all_available(
100+
benchmark: BenchmarkFixture, ai_benchmark_task: Task, num_channels: int, num_samples: int
101+
) -> None:
102+
reader = AnalogMultiChannelReader(ai_benchmark_task.in_stream)
103+
# This test reads the whole buffer, which is 2x num_samples.
104+
data = numpy.full((num_channels, num_samples * 2), math.inf, dtype=numpy.float64)
105+
106+
benchmark(reader.read_many_sample, data, READ_ALL_AVAILABLE)
107+
108+
84109
@pytest.mark.benchmark(group="analog_readers")
85110
@pytest.mark.parametrize("num_channels", [1, 2, 8])
86111
@pytest.mark.parametrize("num_samples", [1, 1000])

0 commit comments

Comments
 (0)