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.
精彩评论