File tree Expand file tree Collapse file tree 5 files changed +89
-0
lines changed Expand file tree Collapse file tree 5 files changed +89
-0
lines changed Original file line number Diff line number Diff line change @@ -114,6 +114,33 @@ def _wrapper(*args, **kwargs):
114114 decorated_func .unit = "Mb"
115115 return _wrapper
116116
117+ @staticmethod
118+ def decorator_repeating (repeats = 3 ):
119+ """Benchmark to track growth in resident memory during execution.
120+
121+ Tracks memory for repeated calls of decorated function.
122+
123+ Intended for use on ASV ``track_`` benchmarks. Applies the
124+ :class:`TrackAddedMemoryAllocation` context manager to the benchmark
125+ code, sets the benchmark ``unit`` attribute to ``Mb``.
126+
127+ """
128+
129+ def decorator (decorated_func ):
130+ def _wrapper (* args , ** kwargs ):
131+ assert decorated_func .__name__ [:6 ] == "track_"
132+ # Run the decorated benchmark within the added memory context
133+ # manager.
134+ with TrackAddedMemoryAllocation () as mb :
135+ for _ in range (repeats ):
136+ decorated_func (* args , ** kwargs )
137+ return mb .addedmem_mb ()
138+
139+ decorated_func .unit = "Mb"
140+ return _wrapper
141+
142+ return decorator
143+
117144
118145def on_demand_benchmark (benchmark_object ):
119146 """Disable these benchmark(s) unless ON_DEMAND_BENCHARKS env var is set.
Original file line number Diff line number Diff line change 88
99from iris .cube import CubeList
1010
11+ from . import TrackAddedMemoryAllocation
1112from .generate_data .stock import realistic_4d_w_everything
1213
1314
@@ -33,6 +34,10 @@ def setup(self):
3334 def time_merge (self ):
3435 _ = self .cube_list .merge_cube ()
3536
37+ @TrackAddedMemoryAllocation .decorator_repeating ()
38+ def track_mem_merge (self ):
39+ _ = self .cube_list .merge_cube ()
40+
3641
3742class Concatenate :
3843 # TODO: Improve coverage.
@@ -50,3 +55,7 @@ def setup(self):
5055
5156 def time_concatenate (self ):
5257 _ = self .cube_list .concatenate_cube ()
58+
59+ @TrackAddedMemoryAllocation .decorator_repeating ()
60+ def track_mem_merge (self ):
61+ _ = self .cube_list .concatenate_cube ()
Original file line number Diff line number Diff line change 1414from iris .analysis import AreaWeighted , PointInCell
1515from iris .coords import AuxCoord
1616
17+ from . import TrackAddedMemoryAllocation
18+
1719
1820class HorizontalChunkedRegridding :
1921 def setup (self ) -> None :
@@ -51,6 +53,20 @@ def time_regrid_area_w_new_grid(self) -> None:
5153 # Realise data
5254 out .data
5355
56+ @TrackAddedMemoryAllocation .decorator_repeating ()
57+ def track_mem_regrid_area_w (self ) -> None :
58+ # Regrid the chunked cube
59+ out = self .cube .regrid (self .template_cube , self .scheme_area_w )
60+ # Realise data
61+ out .data
62+
63+ @TrackAddedMemoryAllocation .decorator_repeating ()
64+ def track_mem_regrid_area_w_new_grid (self ) -> None :
65+ # Regrid the chunked cube
66+ out = self .chunked_cube .regrid (self .template_cube , self .scheme_area_w )
67+ # Realise data
68+ out .data
69+
5470
5571class CurvilinearRegridding :
5672 def setup (self ) -> None :
@@ -93,3 +109,10 @@ def time_regrid_pic(self) -> None:
93109 out = self .cube .regrid (self .template_cube , self .scheme_pic )
94110 # Realise the data
95111 out .data
112+
113+ @TrackAddedMemoryAllocation .decorator_repeating ()
114+ def track_mem_regrid_pic (self ) -> None :
115+ # Regrid the cube onto the template.
116+ out = self .cube .regrid (self .template_cube , self .scheme_pic )
117+ # Realise the data
118+ out .data
Original file line number Diff line number Diff line change 88from iris .analysis .stats import pearsonr
99import iris .tests
1010
11+ from . import TrackAddedMemoryAllocation
12+
1113
1214class PearsonR :
1315 def setup (self ):
@@ -30,9 +32,21 @@ def setup(self):
3032 def time_real (self ):
3133 pearsonr (self .cube_a , self .cube_b , weights = self .weights )
3234
35+ @TrackAddedMemoryAllocation .decorator_repeating ()
36+ def track_real (self ):
37+ pearsonr (self .cube_a , self .cube_b , weights = self .weights )
38+
3339 def time_lazy (self ):
3440 for cube in self .cube_a , self .cube_b :
3541 cube .data = cube .lazy_data ()
3642
3743 result = pearsonr (self .cube_a , self .cube_b , weights = self .weights )
3844 result .data
45+
46+ @TrackAddedMemoryAllocation .decorator_repeating ()
47+ def track_lazy (self ):
48+ for cube in self .cube_a , self .cube_b :
49+ cube .data = cube .lazy_data ()
50+
51+ result = pearsonr (self .cube_a , self .cube_b , weights = self .weights )
52+ result .data
Original file line number Diff line number Diff line change 1313import iris
1414from iris .analysis .trajectory import interpolate
1515
16+ from . import TrackAddedMemoryAllocation
17+
1618
1719class TrajectoryInterpolation :
1820 def setup (self ) -> None :
@@ -33,8 +35,22 @@ def time_trajectory_linear(self) -> None:
3335 # Realise the data
3436 out_cube .data
3537
38+ @TrackAddedMemoryAllocation .decorator_repeating ()
39+ def track_trajectory_linear (self ) -> None :
40+ # Regrid the cube onto the template.
41+ out_cube = interpolate (self .cube , self .sample_points , method = "linear" )
42+ # Realise the data
43+ out_cube .data
44+
3645 def time_trajectory_nearest (self ) -> None :
3746 # Regrid the cube onto the template.
3847 out_cube = interpolate (self .cube , self .sample_points , method = "nearest" )
3948 # Realise the data
4049 out_cube .data
50+
51+ @TrackAddedMemoryAllocation .decorator_repeating ()
52+ def track_trajectory_nearest (self ) -> None :
53+ # Regrid the cube onto the template.
54+ out_cube = interpolate (self .cube , self .sample_points , method = "nearest" )
55+ # Realise the data
56+ out_cube .data
You can’t perform that action at this time.
0 commit comments