开发者

Which one of these two MATLAB string concatenation methods is faster?

Which one of the following ways开发者_开发知识库 to concatenate two strings is the fastest?

test = ['ssd' 'sdsd'];

 

test = sprintf('%s%s', string1, string2);


A very simple test reveals that

test = ['ssd''sdsd'];

is faster.

Specifically:

tic; for t=1:10000; test = ['ssd' 'sdsd']; end; toc;                
Elapsed time is 0.105972 seconds.

while

tic; for t=1:10000; test = sprintf('%s%s', 'ssd', 'sdsd'); end; toc;
Elapsed time is 0.211863 seconds.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜