MATLABで同じクラスの多数のインスタンスを管理するための最良の方法は何でしょうか?
素朴な方法を使用すると、異常な結果が生成されます。
classdef Request
properties
num=7;
end
methods
function f=foo(this)
f = this.num + 4;
end
end
end
>> a=[];
>> tic,for i=1:1000 a=[a Request];end;toc
Elapsed time is 5.426852 seconds.
>> tic,for i=1:1000 a=[a Request];end;toc
Elapsed time is 31.261500 seconds.
ハンドルを継承すると、結果が大幅に向上します。
classdef RequestH < handle
properties
num=7;
end
methods
function f=foo(this)
f = this.num + 4;
end
end
end
>> tic,for i=1:1000 a=[a RequestH];end;toc
Elapsed time is 0.097472 seconds.
>> tic,for i=1:1000 a=[a RequestH];end;toc
Elapsed time is 0.134007 seconds.
>> tic,for i=1:1000 a=[a RequestH];end;toc
Elapsed time is 0.174573 seconds.
ただし、特に再割り当てのオーバーヘッドの増加を考慮すると、まだ許容できるパフォーマンスではありません
クラス配列を事前に割り当てる方法はありますか?オブジェクトの大量のオブジェクトを効果的に管理する方法についてのアイデアはありますか?
ありがとう、
ダニ