Skip to content

Commit df45769

Browse files
authored
Merge pull request refnx#882 from andyfaff/lib
BENCH: add event reading
2 parents 7a147ff + e3b9ab7 commit df45769

3 files changed

Lines changed: 66 additions & 0 deletions

File tree

benchmarks/asv.conf.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@
6262
"pip": [],
6363
"meson": [],
6464
"ninja": [],
65+
"pandas": [],
66+
"h5py": [],
6567
},
6668

6769
"build_command": "python -mpip wheel --no-deps --no-build-isolation --no-index -w {build_cache_dir} {build_dir}",

benchmarks/benchmarks/_lib.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import numpy as np
2+
3+
from .common import Benchmark

benchmarks/benchmarks/reduce.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)