This repository was archived by the owner on Apr 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathbenchmark_hardware.m
More file actions
151 lines (100 loc) · 3.36 KB
/
Copy pathbenchmark_hardware.m
File metadata and controls
151 lines (100 loc) · 3.36 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function filename = benchmark_hardware(varargin)
% benchmark_hardware Perform a simple hardware benchmark
%
% Performs a simple benchmark of the computer that can be later used to normalize
% the speed estimate between results obtained on different hardware.
%
% Output:
% - filename: Path to the local performance profile.
%
filename = fullfile(get_global_variable('directory'), 'cache', 'performance.txt');
if exist(filename, 'file')
print_debug('Skipping hardware performance benchmark');
return;
end;
print_text('Performing hardware performance benchmark');
print_indent(1);
performance = struct('reading', NaN, ...
'convolution_native', NaN, 'convolution_matlab', NaN, ...
'nonlinear_native', NaN);
repetitions = 20;
temporary_dir = tempdir;
image_file = fullfile(temporary_dir, 'image.jpg');
print_debug('Performing IO image reading benchmark');
I = rand(600, 600);
imwrite(I, image_file);
tic;
for i = 1:repetitions
imread(image_file);
end;
performance.reading = toc / repetitions;
delete(image_file);
print_debug('Performing native convolution filter benchmark');
I = rand(600, 600);
K = rand(30, 30);
tic;
for i = 1:repetitions
benchmark_native('convolution', I, K);
end;
performance.convolution_native = toc / repetitions;
print_debug('Performing Matlab convolution filter benchmark');
I = rand(600, 600);
K = rand(30, 30);
tic;
for i = 1:repetitions
conv2(I, K);
end;
performance.convolution_matlab = toc / repetitions;
print_debug('Performing native nonlinear max filter benchmark');
I = rand(600, 600);
tic;
for i = 1:repetitions
benchmark_native('maxfilter', I, 20, 20);
end;
performance.nonlinear_native = toc / repetitions;
if ~is_octave()
print_debug('Performing Matlab startup time benchmark');
time_file = fullfile(pwd, 'time.txt');
if isunix
matlab_executable = [fullfile(strrep(matlabroot, ' ', '\ '), 'bin', 'matlab'), ' -nodesktop -nosplash -r "dlmwrite(''', time_file, ''', now, ''precision'', 30); quit;"'];
else
matlab_executable = ['"', fullfile(matlabroot, 'bin', 'matlab.exe'), '" -nodesktop -nosplash -wait -minimize -r "dlmwrite(''', time_file, ''', now, ''precision'', 30); quit;"'];
end
try
repetitions = 3;
totaltime = 0;
for i = 1:repetitions
if exist(time_file, 'file')
delete(time_file);
end;
startime = now;
if verLessThan('matlab', '7.14.0')
[result, output] = system(matlab_executable);
else
[result, output] = system(matlab_executable, '');
end;
endtime = NaN;
for w = 1:500
if exist(time_file, 'file')
endtime = csvread(time_file);
delete(time_file);
break;
end;
pause(0.1);
end;
if isnan(endtime)
print_debug('ERROR: Unable to time Matlab: timeout.');
end;
totaltime = totaltime + (endtime - startime) * 86400;
end;
performance.matlab_startup = totaltime / repetitions;
catch e
print_debug('ERROR: Exception thrown "%s".', e.message);
end;
end
[platform_str,platform_maxsize,platform_endian] = computer();
performance.platform = platform_str;
performance.platform_maxsize = platform_maxsize;
performance.platform_endian = platform_endian;
writestruct(filename, performance);
print_indent(-1);