% TimeTrial: Speed comparison of Matlab 2020b vs Octave 6.1 for a variety
% of signal processing tasks, including plotting and printing. Displays the
% elapsed time on your computer, followed by the times previously measured
% on several several other hardware and software platforms. Finally, the
% total elapsed time in seconds for the entire set is displayed.

clocktime=clock;
StartTime=(clocktime(4)+clocktime(5)/60+clocktime(6))/(60*60);
save StartTime

disp('1')
disp('Conventional "for loop" vs vector/matrix notation (Matlab timing) Loop:')
k=1000;B=zeros(k,k);tic;x=1:k;for n=1:k;B(:,n)=n.*x;end;toc1=toc;
disp('Matlab 2020b:  0.0030898 seconds.')
disp('Matlab 2017b: .006 seconds.')
disp('Matlab 2009:  1.446651 seconds.')
disp('Matlab Online, R2018b Update 1: 0.003 seconds.')
disp('Octave 6.1.0: 0.004385 seconds.')

disp('2')
disp('Matlab/Octave: vector/matrix notation:')
k=1000;clear A;tic;x=1:k;A=[1:k]'*x;toc2=toc
disp('Matlab 2020b:  0.0008408 seconds.')
disp('Matlab 2017b: 0.0015 seconds.')
disp('Matlab 2009:  0.004306 seconds.')
disp('Matlab Online, R2018b Update 1:  0.0068 seconds.')
disp('Octave 6.1.0: 0.0014789 seconds.')
disp('Time improvement factor for vector/matrix notation:')
disp(toc1/toc2)

disp('3')
disp('Random numbers')
clf;tic;RANDtoRANDN;t1=toc
disp('Matlab 2020b:  0.22488 seconds.')
disp('Matlab 2017b: 4.7 seconds.')
disp('Matlab 2009: 0.11 seconds.')
disp('Matlab Online, R2018b Update 1: 0.36 seconds.')
disp('Octave 6.1.0: 0.8973 seconds.')

disp('4')
disp('Comparison of types of noise') 
clf;tic;noisetest;toc
disp('Matlab 2020b:  1.813346 seconds.')
disp('Matlab 2017b: 4.3 seconds.')
disp('Matlab 2009: 6.5 seconds.')
disp('Matlab Online, R2018, Update 1: 3.996692 seconds.')
disp('Octave 6.1.0: 7.8 seconds.')

disp('5')
disp('Smoothing and plotting')
clf;tic;plot(fastsmooth(randn(1,1000),100,3,0));toc
disp('Matlab 2020b:  0.005722 seconds.')
disp('Matlab 2009: 0.015 seconds.')
disp('Matlab 2017b Home: 0.013 seconds.')
disp('Matlab Online, R2018, Update 1: 0.011 seconds.')
disp('Octave 6.1.0: 1.0 seconds.')

disp('6')
disp('Median filter')
clf;tic;x=-5:.01:5;y=exp(-(x).^2);
for n=1:100:length(x),y(n)=randn(1)+y(n);end
subplot(1,2,1);plot(x,y);title('Before');
subplot(1,2,2);plot(x,medianfilter(y,1));title('After');toc
disp('Matlab 2020b:  0.031724 seconds.')
disp('Matlab 2009: 0.04 seconds.')
disp('Matlab 2017b Home: 0.043 seconds.')
disp('Matlab Online, R2018, Update 1: 0.056 seconds.')
disp('Octave 6.1.0: 0.4771 seconds.')

disp('7')
disp('smoothed second derivative using ProcessSignal')
clf;tic;x=[0:.01:10]';y=10./(1+(x/4).^2)+exp(-(x-5).^2)+.1.*randn(size(x));subplot(2,1,1);plot(x,y);subplot(2,1,2);plot(x,ProcessSignal(x,y,2,60,3,0,0,0,0,0,0,0,0,0,0));toc
disp('Matlab 2020b:  0.018679 seconds.')
disp('Matlab 2009: .03 seconds.')
disp('Matlab 2017b Home: 0.03 seconds.')
disp('Matlab Online, R2018, Update 1: 0.023 seconds.')
disp('Octave 6.1.0: 0.242072 seconds.')

disp('8')
disp('Quantitative analysis by derivative spectroscopy')
clf;tic;DerivativeDemo;toc
disp('Matlab 2020b:  0.088042 seconds.')
disp('Matlab 2009: 0.06 seconds.')
disp('Matlab 2017b Home: 0.2 seconds.')
disp('Matlab Online, R2018, Update 1: 0.23 seconds.')
disp('Octave 6.1.0: 1.6477 seconds.')

disp('9')
disp('Fourier Filter')
clf;tic;plot(FouFilter(tan(1:100000),1,19,2,2,0));toc
disp('Matlab 2020b:  0.008563 seconds.')
disp('Matlab 2009: 0.02 seconds.')
disp('Matlab 2017b Home: 0.012 seconds.')
disp('Matlab Online, R2018, Update 1: 0.134  seconds.')
disp('Octave 6.1.0: 0.1 seconds.')

disp('10')
disp('Polynomial least squares and plotting')
clf;tic;x=0:100;y=100+(x*100)+100.*randn(size(x));[coef,RSquared,~]=plotit(x,y,1);toc
disp('Matlab 2020b:  0.020015 seconds.')
disp('Matlab 2009: 0.0067 seconds.')
disp('Matlab 2017b Home: 0.03 seconds.')
disp('Matlab Online, R2018, Update 1: 0.054 seconds.')
disp('Octave 6.1.0: 0.984 seconds.')

disp('11')
disp('Quadratic Least squares fit to Gaussian peak')
clf;tic;x=50:.1:150;y=100.*gaussian(x,100,100)+10.*randn(size(x));[Height,Position,Width]=gaussfit(x,y);plot(x,y,'o',x,Height.*gaussian(x,Position,Width));toc
disp('Matlab 2020b:  0.004623 seconds.')
disp('Matlab 2009: 0.0024 seconds.')
disp('Matlab 2017b Home: 0.023 seconds.')
disp('Matlab Online, R2018, Update 1: 0.024 seconds.')
disp('Octave 6.1.0: 0.11 seconds.')

disp('12')
disp('Multilinear Regression')
clf;tic;RegressionDemo2;toc
disp('Matlab 2020b:  0.042909 seconds.')
disp('Matlab 2009: 0.015423 seconds.')
disp('Matlab 2017b Home: 0.079676 seconds.')
disp('Matlab Online, R2018, Update 1:  0.1567 seconds.')
disp('Octave 6.1.0: 0.2 seconds.')

disp('13 ')
disp('findpeaks function on noisy synthetic data')
clf;tic;DemoFindPeak;toc
disp('Matlab 2020b:  0.011349 seconds.')
disp('Matlab 2009: 0.12 seconds.')
disp('Matlab 2017b Home: .04 seconds.')
disp('Matlab Online, R2018, Update 1: 0.060 seconds.')
disp('Octave 6.1.0: 0.3 seconds.')

disp('14 ')
disp('Demo Find Peak SNR')
clf;tic;DemoFindPeakSNR;toc
disp('Matlab 2020b:  0.018744 seconds.')
disp('Matlab 2009: 0.16 seconds.')
disp('Matlab 2017b Home: .05 seconds.')
disp('Matlab Online, R2018, Update 1: .045 seconds.')
disp('Octave 6.1.0: 2.5 seconds.')

disp('15 ')
disp('Peakfit.m with plotting enabled')
clf;tic;x=0:.1:10;y=exp(-(x-5).^2);peakfit([x' y']);toc
disp('Matlab 2020b:  0.043675 seconds.')
disp('Matlab 2009: 0.03 seconds.')
disp('Matlab 2017b Home: 0.06 seconds.')
disp('Matlab Online, R2018, Update 1: 0.11 seconds.')
disp('Octave 6.1.0: 0.34 seconds.')

disp('16 ')
disp('first-order least-squares fit error propagation')
clf;tic;LinearFiMC;toc
disp('Matlab 2020b:  0.0262 seconds.')
disp('Matlab 2009: 0.574 seconds.')
disp('Matlab 2017b Home: 0.4 seconds.')
disp('Matlab Online, R2018, Update 1: 0.9 seconds.')
disp('Octave 6.1.0:  0.270638 seconds.')

disp('17 ')
disp('first-order least-squares fit error propagation by bootstrap')
clf;tic;TestLinearFit;toc
disp('Matlab 2020b:  0.324696 seconds.')
disp('Matlab 2009: 0.44 seconds.')
disp('Matlab 2017b Home: 3.4 seconds.')
disp('Matlab Online, R2018, Update 1: 3.1 seconds.')
disp('Octave 6.1.0: 0.290768 seconds.')

disp('18 ')
disp('Monte Carlo comparison of full-peak iterative fit with Gaussfit method.')
clf;tic;GaussFitMC2(100,100,100,50,1,1000);toc
disp('Matlab 2020b:  1.764122 seconds.')
disp('Matlab 2009: 7 seconds.')
disp('Matlab 2017b Home: 5.6 seconds.')
disp('Matlab Online, R2018, Update 1: 4.7 seconds.')
disp('Octave 6.1.0: 8.86045 seconds.')

% FinishTime=time;
disp('END OF TIME TRIAL')
clocktime=clock;
EndTime=(clocktime(5)+clocktime(6))/60;
load StartTime
TotalElapsedTimeInSeconds=(EndTime-StartTime)*60