📄 testmergesorted.m
字号:
clc,clear all
orga=sort(rand(1,2000000)); % generate 2 million random numbers and sort them (first vector)
orgb=sort(rand(1,2500000)); % generate 2.5 million random numbers and sort them (second vector)
% % Merging two sorted vectors using 'mergesorted' function
a=orga;
b=orgb;
time = cputime;
c2=mergesorted(a,b);
time_mergesorted = cputime-time
% % Merging two sorted vectors using MATLAB built in functions
a=orga;
b=orgb;
time = cputime;
c1=sort([a,b]);
time_builtin = cputime-time
if(~isequal(c1,c2) || ~issorted(c1) || ~issorted(c2) )
error('problem: report to author')
end
TimeRatio=time_builtin/time_mergesorted
% % Copyright
% % This program or any other program(s) supplied with it does not
% % provide any warranty direct or implied. This program is free to
% % use/share for non-commerical purpose only as long as author is referenced.
% % For commerical purpose usage contact with author:
% % contact: M A Khan
% % Email: khan_goodluck@yahoo.com
% % http://www.m-a-khan.blinkz.com/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -