Closed
Description
Related to #368
From line_profiler
@wholmgren, you stated that loading the matlab file was one of the two bottlenecks.
Loading the file is pretty slow, and we are doing it each time we run the function. Could we cache the file in the module to avoid reloading it?
There are actually two ways to see that:
- Loading the file when we first call
lookup_linke_turbidity
CACHE = {}
[...]
def lookup_linke_turbidity(...):
[...]
# try to get `LinkeTurbidity` data from the `CACHE`
mat = CACHE.get('LinkeTurbidity')
if not mat:
# load `LinkeTurbidity` data and save then to the `CACHE`
mat = scipy.io.loadmat(filepath)
CACHE['LinkeTurbidity'] = mat
[...]
- Loading the file at import time, and cache it
CACHE = {}
def load_linke_turbidity():
# scipy import try except + filepath
CACHE['LinkeTurbidity'] = scipy.io.loadmat(filepath)
load_linke_turbidity()
[...]
def lookup_linke_turbidity(...):
[...]
# try to get `LinkeTurbidity` data from the `CACHE`
mat = CACHE.get('LinkeTurbidity')
[...]