Commit cb9546e1 by wzc-a

增加大型算例的运行时间比较

parent d0c890f5
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -34,6 +34,8 @@ function compare_results(case_name) ...@@ -34,6 +34,8 @@ function compare_results(case_name)
@cal_runpf @cal_runpf
}; };
% 依次比较每个矩阵 % 依次比较每个矩阵
for i = 1:length(field_names) for i = 1:length(field_names)
field_name = field_names{i}; field_name = field_names{i};
...@@ -48,17 +50,34 @@ function compare_results(case_name) ...@@ -48,17 +50,34 @@ function compare_results(case_name)
continue; continue;
end end
tensor_r = parsed_results.(tensor_field); tensor_result = parsed_results.(tensor_field);
if isempty(tensor_r) if isempty(tensor_result.matrix)
fprintf('%s 矩阵为空\n', field_name); fprintf('%s 矩阵为空\n', field_name);
continue;
end end
% 计算 matpower 的矩阵 % 记录matlab执行时间
matlab_start = tic;
matpower_r = cal_maker(case_name); matpower_r = cal_maker(case_name);
matlab_time = toc(matlab_start);
% 输出时间比较
tensoreval_time = tensor_result.tensoreval_time;
% 添加时间比较表头
fprintf('\n时间比较结果:\n');
fprintf('%-15s %-12s %-12s %-12s\n', '测试项目', 'TensorEval', 'MATLAB', '比较');
fprintf('%s\n', repmat('-', 1, 55));
fprintf('%-15s %-5.4fs %-5.4fs ', field_name, tensoreval_time, matlab_time);
if matlab_time > tensoreval_time
speedup = matlab_time / tensoreval_time;
fprintf(' %.2fx faster\n', speedup);
else
slowdown = tensoreval_time / matlab_time;
fprintf(' %.2fx slower\n', slowdown);
end
% 比较矩阵 % 比较矩阵
compare_matrices(tensor_r, matpower_r, field_name); compare_matrices(tensor_result.matrix, matpower_r, field_name);
end end
fprintf('\n所有比较完成!\n\n'); fprintf('\n所有比较完成!\n\n');
......
function results = execute_and_parse() function results = execute_and_parse()
% 执行命令行并解析复数矩阵结果 % 执行命令行并解析复数矩阵结果
% 返回一个结构体,包含所有测试文件的解析结果 % 返回一个结构体,包含所有测试文件的解析结果和tensoreval执行时间
% 设置路径和文件 % 设置路径和文件
tensoreval_path = '..\..\..\eig-rc\target\release\examples\tensoreval.exe'; tensoreval_path = '..\..\..\eig-rc\target\release\examples\tensoreval.exe';
...@@ -22,23 +22,38 @@ function results = execute_and_parse() ...@@ -22,23 +22,38 @@ function results = execute_and_parse()
test_file = test_files{i}; test_file = test_files{i};
fprintf('正在处理: %s\n', test_file); fprintf('正在处理: %s\n', test_file);
% 构建并执行命令 % 构建并执行命令,记录执行时间
cmd = sprintf('%s --complex --verbose %s', tensoreval_path, test_file); cmd = sprintf('%s --complex --verbose %s', tensoreval_path, test_file);
tensoreval_start = tic;
[status, output] = system(cmd); [status, output] = system(cmd);
tensoreval_time = toc(tensoreval_start);
% 解析结果 % 解析结果
if status == 0 && ~isempty(strtrim(output)) if status == 0 && ~isempty(strtrim(output))
try try
parsed_matrix = parse_complex_matrix_from_output(output); parsed_matrix = parse_complex_matrix_from_output(output);
results.(sprintf('test_%d_%s', i, strrep(test_file, '.txt', ''))) = parsed_matrix; field_name = sprintf('test_%d_%s', i, strrep(test_file, '.txt', ''));
fprintf(' 成功解析矩阵: %dx%d\n', size(parsed_matrix, 1), size(parsed_matrix, 2)); results.(field_name) = struct(...
'matrix', parsed_matrix, ...
'tensoreval_time', tensoreval_time, ...
'file', test_file ...
);
fprintf(' 成功解析矩阵: %dx%d,执行时间: %.4fs\n', size(parsed_matrix, 1), size(parsed_matrix, 2), tensoreval_time);
catch ME catch ME
fprintf(' 解析失败: %s\n', ME.message); fprintf(' 解析失败: %s\n', ME.message);
results.(sprintf('test_%d_%s', i, strrep(test_file, '.txt', ''))) = []; results.(sprintf('test_%d_%s', i, strrep(test_file, '.txt', ''))) = struct(...
'matrix', [], ...
'tensoreval_time', tensoreval_time, ...
'file', test_file ...
);
end end
else else
fprintf(' 无输出或执行失败\n'); fprintf(' 无输出或执行失败\n');
results.(sprintf('test_%d_%s', i, strrep(test_file, '.txt', ''))) = []; results.(sprintf('test_%d_%s', i, strrep(test_file, '.txt', ''))) = struct(...
'matrix', [], ...
'tensoreval_time', tensoreval_time, ...
'file', test_file ...
);
end end
end end
...@@ -47,11 +62,11 @@ function results = execute_and_parse() ...@@ -47,11 +62,11 @@ function results = execute_and_parse()
% 显示结果概要 % 显示结果概要
fieldNames = fieldnames(results); fieldNames = fieldnames(results);
for i = 1:length(fieldNames) for i = 1:length(fieldNames)
matrix = results.(fieldNames{i}); result = results.(fieldNames{i});
if ~isempty(matrix) if ~isempty(result.matrix)
fprintf('%s: %dx%d 复数矩阵\n', fieldNames{i}, size(matrix, 1), size(matrix, 2)); fprintf('%s: %dx%d 复数矩阵,TensorEval时间: %.4fs\n', fieldNames{i}, size(result.matrix, 1), size(result.matrix, 2), result.tensoreval_time);
else else
fprintf('%s: 空矩阵\n', fieldNames{i}); fprintf('%s: 空矩阵,TensorEval时间: %.4fs\n', fieldNames{i}, result.tensoreval_time);
end end
end end
end end
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论