8000 RFC: refactor benchmarks setups and customize pytest's discovery rule… · astropy/astropy-benchmarks@9531a80 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 9531a80

Browse files
committed
RFC: refactor benchmarks setups and customize pytest's discovery rule to enable running benchmarks through pytest
1 parent ba0d89f commit 9531a80

File tree

14 files changed

+102
-0
lines changed

14 files changed

+102
-0
lines changed

benchmarks/coordinates.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def setup(self):
5151
self.array_rep = CartesianRepresentation(np.ones((3, 1000)) * u.kpc)
5252
self.array_dif = CartesianDifferential(np.ones((3, 1000)) * u.km / u.s)
5353

54+
def setup_method(self):
55+
# pytest compat
56+
self.setup()
57< 10000 /code>+
5458
def time_with_differentials_scalar(self):
5559
self.scalar_rep.with_differentials(self.scalar_dif)
5660

@@ -129,6 +133,10 @@ def setup(self):
129133
xyz_clustered2, representation_type=CartesianRepresentation
130134
)
131135

136+
def setup_method(self):
137+
# pytest compat
138+
self.setup()
139+
132140
def time_init_nodata(self):
133141
FK5()
134142

@@ -188,6 +196,10 @@ def setup(self):
188196
lat=self.array_q_dec, lon=self.array_q_ra
189197
)
190198

199+
def setup_method(self):
200+
# pytest compat
201+
self.setup()
202+
191203
def time_init_scalar(self):
192204
SkyCoord(1, 2, unit="deg", frame="icrs")
193205

benchmarks/io_ascii/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def setup(self):
4141
for col, x in izip(self.cols, lst):
4242
col.str_vals = [str(s) for s in x]
4343

44+
def setup_method(self):
45+
# pytest compat
46+
self.setup()
47+
4448
def time_continuation_inputter(self):
4549
core.ContinuationLinesInputter().process_lines(self.lines)
4650

benchmarks/io_ascii/fixedwidth.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ def setup(self):
1818
self.splitter.cols = self.header.cols
1919
self.data = ascii.FixedWidthData()
2020

21+
def setup_method(self):
22+
# pytest compat
23+
self.setup()
24+
2125
def time_splitter(self):
2226
self.splitter(self.lines[1:])
2327

benchmarks/io_ascii/ipac.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ def setup(self):
2626
self.data.cols = list(self.table.columns.values())
2727
self.data._set_fill_values(self.data.cols)
2828

29+
def setup_method(self):
30+
# pytest compat
31+
self.setup()
32+
2933
def time_splitter(self):
3034
self.splitter.join(self.vals, self.widths)
3135

benchmarks/io_ascii/main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def setup(self):
4343
if self.file_format != "sextractor":
4444
self.table = self.read()
4545

46+
def setup_method(self):
47+
# pytest compat
48+
self.setup()
49+
4650
def read(self):
4751
return ascii.read(BytesIO(self.data), format=self.file_format, guess=False)
4852

benchmarks/io_ascii/rdb.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ def setup(self):
1313
self.lines = f.read().split("\n")
1414
f.close()
1515

16+
def setup_method(self):
17+
# pytest compat
18+
self.setup()
19+
1620
def time_get_cols(self):
1721
self.header.get_cols(self.lines)

benchmarks/io_ascii/sextractor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ def setup(self):
2323
self.lines.append("# {} {} Description [pixel**2]".format(i, randword()))
2424
self.lines.append("Non-header line")
2525

26+
def setup_method(self):
27+
# pytest compat
28+
self.setup()
29+
2630
def time_header(self):
2731
self.header.get_cols(self.lines)

benchmarks/io_ascii/table.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ def setup(self):
2828
self.outputter = core.TableOutputter()
2929
self.table = table.Table()
3030

31+
def setup_method(self):
32+
# pytest compat
33+
self.setup()
34+
3135
def time_table_outputter(self):
3236
self.outputter(self.cols, {"table": {}})
3337

benchmarks/io_fits.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ def setup(self):
2525
t["booleans"] = t["floats"] > 0.5
2626
t.write(temp, format="fits")
2727

28+
def setup_method(self):
29+
# pytest compat
30+
self.setup()
31+
2832
def time_read_nommap(self):
2933
try:
3034
Table.read(self.table_file, format="fits", memmap=False)
@@ -66,6 +70,10 @@ def setup(self):
6670
self.hdr = make_header()
6771
self.hdr_string = self.hdr.tostring()
6872

73+
def setup_method(self):
74+
# pytest compat
75+
self.setup()
76+
6977
def time_get_int(self):
7078
self.hdr.get("INT999")
7179

benchmarks/modeling/compound.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def setup(self):
4747
| models.RotateNative2Celestial(5.6, -72.05, 180)
4848
)
4949

50+
def setup_method(self):
51+
# pytest compat
52+
self.setup()
53+
5054
def time_scalar(self):
5155
r, d = self.model(x_no_units_scalar, x_no_units_scalar)
5256

@@ -77,6 +81,10 @@ def setup(self):
7781
| models.RotateNative2Celestial(5.6 * u.deg, -72.05 * u.deg, 180 * u.deg)
7882
)
7983

84+
def setup_method(self):
85+
# pytest compat
86+
self.setup()
87+
8088
def time_scalar(self):
8189
r, d = self.model(x_no_units_scalar * u.pix, x_no_units_scalar * u.pix)
8290

0 commit comments

Comments
 (0)
0