-
Notifications
You must be signed in to change notification settings - Fork 0
/
mex_time.m
61 lines (49 loc) · 1.37 KB
/
mex_time.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function mex_time(language, verbose)
% MEX_TIME measures the running time of MATLAB concerning MEX.
orig_warning_state = warning;
warning('off','all');
if nargin >= 1 && (isa(language, 'char') || isa(language, 'string')) && strcmpi(language, 'Fortran')
language = 'Fortran';
timestwo_src = 'timestwo.F';
else
language = 'C';
timestwo_src = 'timestwo.c';
end
if nargin <= 1
verbose = false;
end
if nargin >= 2 && (isa(verbose, 'char') || isa(verbose, 'string')) && strcmpi(verbose, 'verbose')
verbose = true;
end
if verbose
mex_options = {'-v'};
else
mex_options = {};
end
if ismac
sys = 'macOS';
elseif isunix
sys = 'GNU/Linux';
elseif ispc
sys = 'Windows';
else
error('Platform not supported.')
end
matlab_version = version('-release');
date_time = datestr(now,'yyyy.mm.dd HH:MM:SS');
fprintf('\nSystem: %s | Language: %s | MATLAB: %s | Time: %s\n\n', sys, language, matlab_version, date_time);
tic;
mex(mex_options{:}, '-setup', language);
fprintf('\n- Time for setting MEX up: %f seconds\n\n', toc);
clear('timestwo');
tic;
mex(mex_options{:}, fullfile(matlabroot, 'extern', 'examples', 'refbook', timestwo_src));
fprintf('\n- Time for mexifying timestwo: %f seconds\n', toc);
tic;
for i = 1 : 100
timestwo(i);
end
fprintf('\n- Time for 100 runs of timestwo: %f seconds\n\n', toc);
delete('timestwo.*');
warning(orig_warning_state);
return