对象:A.m
classdef A
properties
aa
end
methods
function obj=A(a)
obj.aa=a;
end
end
end
测试代码:
clear all
tic
list = [];
for i=1:1000
list= [list,A(i)];
end
toc
clear
tic
list = A.empty(2,0);
for i=1:1000
list(i) = A(i);
end
toc
clear
tic
m1 = containers.Map('KeyType', 'uint32', 'ValueType', 'any');
for i=1:1000
m1(i) = A(i);
end
toc
测试结果:
通过测试结果可以发现直接使用方括号串接的性能最差[],不推荐使用,第二种方法的性能最高。除了通过tic和toc函数测试程序运行的时间外,还可与使用profile viewer探查器来可视化地显示每行代码的运行时间。