MATLABOOP是慢的还是我做错了什么?
a + b
, a == b
, a.find( b )
strcat( a b )
, strcmp( a, b )
strfind( a, b )
问题:放缓
我的测试用例
classdef String < handle .... properties stringobj = ''; end function o = plus( o, b ) o.stringobj = [ o.stringobj b ]; end function n = Length( o ) n = length( o.stringobj ); end function o = SetLength( o, n ) o.stringobj = o.stringobj( 1 : n ); endendfunction atest( a, b ) %plain functions n = length( a ); a = [ a b ]; a = a( 1 : n );function btest( a, b ) %OOP n = a.Length(); a = a + b; a.SetLength( n );function RunProfilerLoop( nLoop, fun, varargin ) profile on; for i = 1 : nLoop fun( varargin{ : } ); end profile off; profile report;a = 'test';aString = String( 'test' );RunProfilerLoop( 1000, @(x,y)atest(x,y), a, 'appendme' );RunProfilerLoop( 1000, @(x,y)btest(x,y), aString, 'appendme' );
结果
Btest 0.550(带String.etLength 0.138,String.plus 0.065,String.Length 0.057)
顶楼0.015
frpintf( 1, 'test\n' )
std::string( "blah" )
std::cout
std::cout << "blah"
在查找类/包函数时,它仅仅是开销吗?
function n = atest( x, y ) n = ctest( x, y ); % ctest is in matlab pathfunction n = btest( x, y ) n = util.ctest( x, y ); % ctest is in +util directory, parent directory is in path
每秒0.004秒,0.001秒
0.060秒,0.014秒
慕森卡
万千封印
相关分类