Skip to content

Commit

Permalink
Template Benchmarks (#957)
Browse files Browse the repository at this point in the history
* create template benchmark

* add grid template, fix typo

* fix failing benchmarks

* add args to setup and teardown

* update args and kwargs

* attempt to fix setup and teardown (1)

* removed unused imports
  • Loading branch information
philipc2 authored Sep 17, 2024
1 parent 3f8929d commit 92f38db
Showing 1 changed file with 34 additions and 68 deletions.
102 changes: 34 additions & 68 deletions benchmarks/mpas_ocean.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,54 +27,56 @@
"120km": [current_path / grid_filename_120, current_path / data_filename_120]}


class Gradient:

param_names = ['resolution']
params = ['480km', '120km']
class DatasetBenchmark:
"""Class used as a template for benchmarks requiring a ``UxDataset`` in
this module across both resolutions."""
param_names = ['resolution',]
params = [['480km', '120km'],]


def setup(self, resolution, *args, **kwargs):


def setup(self, resolution):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])

def teardown(self, resolution):
def teardown(self, resolution, *args, **kwargs):
del self.uxds

def time_gradient(self, resolution):
self.uxds[data_var].gradient()
class GridBenchmark:
"""Class used as a template for benchmarks requiring a ``Grid`` in this
module across both resolutions."""
param_names = ['resolution', ]
params = [['480km', '120km'], ]

def peakmem_gradient(self, resolution):
grad = self.uxds[data_var].gradient()
def setup(self, resolution, *args, **kwargs):

class Integrate:
self.uxgrid = ux.open_grid(file_path_dict[resolution][0])

param_names = ['resolution']
params = ['480km', '120km']
def teardown(self, resolution, *args, **kwargs):
del self.uxgrid


def setup(self, resolution):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])

def teardown(self, resolution):
del self.uxds
class Gradient(DatasetBenchmark):
def time_gradient(self, resolution):
self.uxds[data_var].gradient()

def peakmem_gradient(self, resolution):
grad = self.uxds[data_var].gradient()

class Integrate(DatasetBenchmark):
def time_integrate(self, resolution):
self.uxds[data_var].integrate()

def peakmem_integrate(self, resolution):
integral = self.uxds[data_var].integrate()

class GeoDataFrame:

param_names = ['resolution', 'exclude_antimeridian']
params = [['480km', '120km'],
[True, False]]


def setup(self, resolution, exclude_antimeridian):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])
class GeoDataFrame(DatasetBenchmark):
param_names = DatasetBenchmark.param_names + ['exclude_antimeridian']
params = DatasetBenchmark.params + [[True, False]]

def teardown(self, resolution, exclude_antimeridian):
del self.uxds

def time_to_geodataframe(self, resolution, exclude_antimeridian):
self.uxds[data_var].to_geodataframe(exclude_antimeridian=exclude_antimeridian)
Expand All @@ -83,50 +85,23 @@ def peakmem_to_geodataframe(self, resolution, exclude_antimeridian):
gdf = self.uxds[data_var].to_geodataframe(exclude_antimeridian=exclude_antimeridian)


class ConnectivityConstruction:

param_names = ['resolution']
params = ['480km', '120km']


def setup(self, resolution):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])


def teardown(self, resolution):
del self.uxds

class ConnectivityConstruction(DatasetBenchmark):
def time_n_nodes_per_face(self, resolution):
self.uxds.uxgrid.n_nodes_per_face

def time_face_face_connectivity(self, resolution):
ux.grid.connectivity._populate_face_face_connectivity(self.uxds.uxgrid)


class MatplotlibConversion:
param_names = ['resolution', 'periodic_elements']
params = (['480km', '120km'], ['include', 'exclude', 'split'])

def setup(self, resolution, periodic_elements):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])

def teardown(self, resolution, periodic_elements):
del self.uxds
class MatplotlibConversion(DatasetBenchmark):
param_names = DatasetBenchmark.param_names + ['periodic_elements']
params = DatasetBenchmark.params + [['include', 'exclude', 'split']]

def time_dataarray_to_polycollection(self, resolution, periodic_elements):
self.uxds[data_var].to_polycollection()


class ConstructTreeStructures:
param_names = ['resolution']
params = ['480km', '120km']

def setup(self, resolution):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])

def teardown(self, resolution):
del self.uxds

class ConstructTreeStructures(DatasetBenchmark):
def time_kd_tree(self, resolution):
self.uxds.uxgrid.get_kd_tree()

Expand Down Expand Up @@ -166,15 +141,6 @@ def time_inverse_distance_weighted_remapping(self):
self.uxds_480["bottomDepth"].remap.inverse_distance_weighted(self.uxds_120.uxgrid)


class HoleEdgeIndices:
param_names = ['resolution']
params = ['480km', '120km']

def setup(self, resolution):
self.uxds = ux.open_dataset(file_path_dict[resolution][0], file_path_dict[resolution][1])

def teardown(self, resolution):
del self.uxds

class HoleEdgeIndices(DatasetBenchmark):
def time_construct_hole_edge_indices(self, resolution):
ux.grid.geometry._construct_hole_edge_indices(self.uxds.uxgrid.edge_face_connectivity)

0 comments on commit 92f38db

Please sign in to comment.