From c627c9cd0e4adc0cdc5a77e1edeb3bbd9b164118 Mon Sep 17 00:00:00 2001 From: dcherian Date: Thu, 6 Apr 2023 21:14:26 -0600 Subject: [PATCH] [skip-ci] Add alignment benchmarks --- asv_bench/asv.conf.json | 3 ++- asv_bench/benchmarks/alignment.py | 45 +++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 asv_bench/benchmarks/alignment.py diff --git a/asv_bench/asv.conf.json b/asv_bench/asv.conf.json index 6f8a306fc43..f8387aca856 100644 --- a/asv_bench/asv.conf.json +++ b/asv_bench/asv.conf.json @@ -68,7 +68,8 @@ "distributed": [""], "flox": [""], "numpy_groupies": [""], - "sparse": [""] + "sparse": [""], + "cftime": [""] }, diff --git a/asv_bench/benchmarks/alignment.py b/asv_bench/benchmarks/alignment.py new file mode 100644 index 00000000000..fafacbd2623 --- /dev/null +++ b/asv_bench/benchmarks/alignment.py @@ -0,0 +1,45 @@ +import numpy as np + +import xarray as xr + +from . import parameterized, requires_dask + +ntime = 365 * 30 +nx = 50 +ny = 50 + + +class Align: + def setup(self, *args, **kwargs): + data = np.random.RandomState(0).randn(ntime, nx, ny) + self.ds = xr.Dataset( + {"temperature": (("time", "x", "y"), data)}, + coords={ + "time": xr.date_range("2000", periods=ntime), + "x": np.arange(nx), + "y": np.arange(ny), + }, + ) + self.year = self.ds.time.dt.year + + @parameterized(["join"], [("outer", "inner", "left", "right", "exact", "override")]) + def time_already_aligned(self, join): + xr.align(self.ds, self.year, join=join) + + @parameterized(["join"], [("outer", "inner", "left", "right")]) + def time_not_aligned(self, join): + xr.align(self.ds, self.year[-100:], join=join) + + +class AlignCFTime(Align): + def setup(self, *args, **kwargs): + super().setup() + self.ds["time"] = xr.date_range("2000", periods=ntime, calendar="noleap") + self.year = self.ds.time.dt.year + + +class AlignDask(Align): + def setup(self, *args, **kwargs): + requires_dask() + super().setup() + self.ds = self.ds.chunk({"time": 100})