Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add elapsedTime function #229

Merged
merged 7 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/utils/elapsedTime.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function [startTime, runTime] = elapsedTime(input, startTime, runTime, nbIteration)
%
% USAGE::
%
% [start, runTime] = elapsedTime(input, startTime, runTime, nbIteration)
%
%
% (C) Copyright 2021 CPP_SPM developers

if nargin < 3
runTime = [];
end

switch input

case 'start'

startTime = tic;

case 'stop'

fprintf('\n\n********* Done :) *********\n\n');

fprintf(' elapsed time is: ')
t=toc(startTime(end));
disp(datestr(datenum(0,0,0,0,0,t),'HH:MM:SS'));

runTime(end+1) = t;
ETA = mean(runTime) * (nbIteration - numel(runTime));
fprintf('\n ETA: ')
disp(datestr(datenum(0,0,0,0,0,ETA),'HH:MM:SS'));

fprintf('\n***************************\n\n');

case 'globalStart'

startTime = tic;

case 'globalStop'

fprintf('\n\n********* Pipeline done :) *********\n\n');
fprintf(' global elapsed time is: ')
t=toc(startTime);
disp(datestr(datenum(0,0,0,0,0,t),'HH:MM:SS'));
fprintf('\n************************************\n\n');

end
11 changes: 11 additions & 0 deletions src/workflows/cleanUpWorkflow.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function cleanUpWorkflow(opt)
%
% USAGE::
%
% cleanUpWorkflow(opt)
%
% (C) Copyright 2021 CPP_SPM developers

elapsedTime('globalStop', opt.globalStart);

end
2 changes: 2 additions & 0 deletions src/workflows/setUpWorkflow.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
% - :group:
%

opt.globalStart = elapsedTime('globalStart');

opt = loadAndCheckOptions(opt);

% load the subjects/Groups information and the task name
Expand Down
26 changes: 26 additions & 0 deletions tests/test_elapsedTime.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function test_suite = test_elapsedTime %#ok<*STOUT>
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions = localfunctions(); %#ok<*NASGU>
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite;
end

function test_elapsedTime_basic()

opt.globalStart = elapsedTime('globalStart');

nbIteration = 5;
runTime = [];

for i=1:nbIteration
subjectStart = elapsedTime('start');
pause(2);
[~, runTime] = elapsedTime('stop', subjectStart, runTime, nbIteration);
end

pause(1);

cleanUpWorkflow(opt)

end