Skip to content

Commit

Permalink
ENH - utilize persistent variables for speedup (fieldtrip#2192)
Browse files Browse the repository at this point in the history
* ENH - utilize persistent variables for speedup

* ENH - initialize persistent variable to false, just to be sure
  • Loading branch information
schoffelen authored Jun 26, 2024
1 parent 2d816e0 commit 8d3377c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ft_defaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@
end

% ft_warning is located in fieldtrip/utilities, which may not be on the path yet
if ~exist('ft_warning', 'file')
if ~initialized && ~exist('ft_warning', 'file')
ft_warning = @warning;
end

% locate the file with the persistent FieldTrip preferences
fieldtripprefs = fullfile(prefdir, 'fieldtripprefs.mat');
if exist(fieldtripprefs, 'file')
if ~initialized && exist(fieldtripprefs, 'file')
prefs = load(fieldtripprefs); % the file contains multiple fields
ft_default = mergestruct(ft_default, prefs);
end
Expand Down
11 changes: 10 additions & 1 deletion utilities/memtic.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,23 @@
% $Id$

persistent state
persistent mexfile_exists

if nargin<1
action = 'tic';
end

if isempty(mexfile_exists)
mexfile_exists = false;
end

if ~mexfile_exists
mexfile_exists = isempty(strfind(which('memprofile'), mexext));
end

% the memtic/memtoc functions make use of a low-level mex file that interacts directly with the operating system
% do not fail if the mex file does not exist
if isempty(strfind(which('memprofile'), mexext))
if mexfile_exists
switch action
case 'tic'
if nargout
Expand Down

0 comments on commit 8d3377c

Please sign in to comment.