Skip to content

Commit

Permalink
first attempt at benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
rcomer committed Jan 12, 2024
1 parent f1c970a commit 045ce02
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions benchmarks/benchmarks/stats.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright Iris contributors
#
# This file is part of Iris and is released under the BSD license.
# See LICENSE in the root of the repository for full licensing details.
"""Stats benchmark tests."""

import iris
from iris.analysis.stats import pearsonr
import iris.tests


class PearsonR:
def setup(self):
cube_temp = iris.load_cube(
iris.tests.get_data_path(
("NetCDF", "global", "xyt", "SMALL_total_column_co2.nc")
)
)

# Make data non-lazy.
cube_temp.data

self.cube_a = cube_temp[:6]
self.cube_b = cube_temp[20:26]
self.cube_b.replace_coord(self.cube_a.coord("time"))
for name in ["latitude", "longitude"]:
self.cube_b.coord(name).guess_bounds()
self.weights = iris.analysis.cartography.area_weights(self.cube_b)

def time_real(self):
pearsonr(self.cube_a, self.cube_b, weights=self.weights)

def time_lazy(self):
for cube in self.cube_a, self.cube_b:
cube.data = cube.lazy_data()

result = pearsonr(self.cube_a, self.cube_b, weights=self.weights)
result.data

0 comments on commit 045ce02

Please sign in to comment.