|
| 1 | +import zipfile |
| 2 | +import shutil |
| 3 | +import urllib.request |
| 4 | +import os |
| 5 | +import sys |
| 6 | + |
| 7 | +from pathlib import Path |
| 8 | + |
| 9 | +import numpy as np |
| 10 | +from refnx.reduce.event import events |
| 11 | +from .common import Benchmark |
| 12 | + |
| 13 | + |
| 14 | +class Event(Benchmark): |
| 15 | + def setup(self): |
| 16 | + pth = Path( |
| 17 | + os.getcwd(), |
| 18 | + "refnx-testdata-master", |
| 19 | + "data", |
| 20 | + "reduce", |
| 21 | + "DAQ_2012-01-20T21-50-32", |
| 22 | + "DATASET_0", |
| 23 | + ) |
| 24 | + try: |
| 25 | + self.fi = open(pth / "EOS.bin", "rb") |
| 26 | + except FileNotFoundError: |
| 27 | + raise FileNotFoundError(os.listdir(os.getcwd())) |
| 28 | + |
| 29 | + def teardown(self): |
| 30 | + self.fi.close() |
| 31 | + |
| 32 | + def setup_cache(self): |
| 33 | + url = "https://github.com/refnx/refnx-testdata/archive/master.zip" |
| 34 | + |
| 35 | + try: |
| 36 | + # grab the test data |
| 37 | + with ( |
| 38 | + urllib.request.urlopen(url, timeout=5) as response, |
| 39 | + open("master.zip", "wb") as f, |
| 40 | + ): |
| 41 | + shutil.copyfileobj(response, f) |
| 42 | + |
| 43 | + # master.zip is in tmpdir |
| 44 | + with zipfile.ZipFile("master.zip") as zf: |
| 45 | + zf.extractall(path=os.getcwd()) |
| 46 | + |
| 47 | + except (urllib.error.URLError, TimeoutError) as e: |
| 48 | + raise e |
| 49 | + |
| 50 | + def time_events(self): |
| 51 | + # single load from the same EOS.bin file. |
| 52 | + _ = events(self.fi) |
| 53 | + |
| 54 | + def time_events_multi(self): |
| 55 | + # multiple loads from the same EOS.bin file |
| 56 | + f = [[1]] |
| 57 | + end_last_event = [127] |
| 58 | + while len(f[0]): |
| 59 | + f, end_last_event = events( |
| 60 | + self.fi, end_last_event=end_last_event[-1], max_frames=2400 |
| 61 | + ) |
0 commit comments