Skip to content

Commit beb806a

Browse files
drewoldagCopilot
andauthored
Implement simple benchmark to request data from dataset (#404)
* Implement simple benchmark to time request all data for 128 samples of HyraxRandomData. * Apply suggestions from code review Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 821feab commit beb806a

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import tempfile
2+
from pathlib import Path
3+
4+
import numpy as np
5+
6+
from hyrax import Hyrax
7+
8+
9+
class DatasetRequestBenchmarks:
10+
"""Timing benchmarks for requesting data from the Hyrax random dataset"""
11+
12+
def setup(self):
13+
"""Prepare for benchmark by defining and setting up a random dataset"""
14+
self.tmp_dir = tempfile.TemporaryDirectory()
15+
self.input_dir = Path(self.tmp_dir.name)
16+
17+
self.h = Hyrax()
18+
self.h.config["general"]["results_dir"] = str(self.input_dir)
19+
self.h.config["data_set"]["name"] = "HyraxRandomDataset"
20+
21+
num_vectors = 4096
22+
self.h.config["data_set.random_dataset"]["size"] = num_vectors
23+
self.h.config["data_set.random_dataset"]["seed"] = 0
24+
self.h.config["data_set.random_dataset"]["shape"] = [3, 64, 64]
25+
26+
self.ds = self.h.prepare()
27+
28+
self.indexes = np.random.randint(0, num_vectors, size=128, dtype=int)
29+
30+
def time_request_all_data(self):
31+
"""Benchmark the amount of time needed to retrieve all the data from
32+
the random dataset
33+
"""
34+
for indx in self.indexes:
35+
self.ds[indx]

0 commit comments

Comments
 (0)