开发者

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

开发者 https://www.devze.com 2023-03-01 12:27 出处:网络
Which one of the following ways开发者_开发知识库 to concatenate two strings is the fastest? test = [\'ssd\' \'sdsd\'];

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

精彩评论

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