

%***************************************************************************
%* Matlab Benchmark program version 5.0
%*
%* Author : Stefan Steinhaus
%*
%* EMAIL : stefan@steinhaus-net.de
%*
%* This program is public domain. Feel free to copy it freely.
%*
%***************************************************************************
close all;
clear all;
clc
fprintf('!!! MATLAB Benchmark !!!\n')
fprintf('==========================\n')

filename='res.txt';

% Array for test results
res=[];

%* Misc. operation *

% IO test & descriptive statistics
result=0;
tic;
datmat=importdata('../data/Currency2.txt',' ');
Limits_Area=[1,261,522,784,1045,1305,1565,1827,2088,2349,2610,2871,3131,3158];
for k=1:500;
	for j=1:13;
		Year_Data=datmat.data(Limits_Area(j):Limits_Area(j+1)-1,4:37);
		Min_Year=min(Year_Data);
		Max_Year=max(Year_Data);
		Mean_Year=mean(Year_Data);
		GainLoss_Year=100-(Year_Data(1,:)+0.00000001)./(Year_Data(end,:)+0.00000001)*100;
	end;
end;
result=toc;
res=[res ; result];
fprintf('IO test & descriptive statistics_____________________: %g sec.\n', result)

% Loop 1000x1000
a=1;
tic;
for x=1:1000;
	for y=1:1000;
		a=a+x+y;
	end;
end;
result=toc;
res=[res ; result];
fprintf('Loop 1000x1000_______________________________________: %g sec.\n', result)

% 2000x2000 normal random matrix ^1000
b=1+(randn(2000,2000)/100);
tic;
a=b.^1000;
result=toc;
res=[res ; result];
fprintf('2000x2000 normal random matrix ^1000_________________: %g sec.\n', result)

% 10000000 values sorted ascending
clear a;
clear b;
a=rand(10000000,1);
tic;
b=sort(a);
result=toc;
res=[res ; result];
fprintf('10000000 values sorted ascending_____________________: %g sec.\n', result)


%* Analysis *

% FFT over 1048576 values (10 times)
clear a;
clear b;
result=0;
for j=1:10
	a=rand(1048576,1);
	tic;
	b=fft(a);
	v=toc;
	result=result+v;
end
res=[res ; result];
fprintf('FFT over 1048576 values (10 times)___________________: %g sec.\n', result)


%* Algebra *

% Determinant of a 1500x1500 matrix
clear a;
clear b;
a=rand(1500,1500);
tic;
b=det(a);
result=toc;
res=[res ; result];
fprintf('Determinant of a 1500x1500 matrix____________________: %g sec.\n',result)

% Inverse of a 1500x1500 matrix
clear a;
clear b;
a=rand(1500,1500);
tic;
b=inv(a);
result=toc;
res=[res ; result];
fprintf('Inverse of a 1500x1500 matrix________________________: %g sec.\n',result)

% Eigenvalues of a 1200x1200 matrix
clear a;
clear b;
a=rand(1200,1200);
tic;
c=eig(a);
result=toc;
res=[res ; result];
fprintf('Eigenvalues of a 1200x1200 matrix____________________: %g sec.\n',result)

% Cholesky decomposition of a 1500x1500 matrix
clear a;
clear b;
a=rand(1500,1500);
a=a'*a;
tic;
b=chol(a);
result=toc;
res=[res ; result];
fprintf('Cholesky decomposition of a 1500x1500 matrix_________: %g sec.\n',result)

% 1500x1500 cross-product matrix
clear a;
clear b;
a=rand(1500,1500);
tic;
b=a'*a;
result=toc;
res=[res ; result];
fprintf('1500x1500 cross-product of a matrix__________________: %g sec.\n',result)

% Principal components of a 5000x500 matrix
a=0;
b=0;
a=rand(5000,500);
tic;
b=princomp(a);
result=toc;
res=[res ; result];
fprintf('Principal components of a 5000x500 matrix____________: %g sec.\n',result)

%* Number theory *

% Calculation of 10000000 fibonacci numbers
clear a;
clear b;
phi = 1.6180339887498949;
a=floor(1000*rand(10000000,1));
tic;
b=(phi.^a-(-phi).^(-a))/sqrt(5);
result=toc;
res=[res ; result];
fprintf('Calculation of 10000000 fibonacci numbers____________: %g sec.\n',result)

%* Stochastic-statistic *

% Gamma function over a 1500x1500 matrix (10 times)
clear a;
clear b;
result=0;
for j=1:10
	a=rand(1500,1500);
	tic;
	b=gamma(a);
	result=result+toc;
end
res=[res ; result];
fprintf('Gamma function over a 1500x1500 matrix (10times)_____: %g sec.\n',result)

% Erf function over a 1500x1500 matrix (10 times)
clear a;
clear b;
result=0;
for j=1:10
	a=rand(1500,1500);
	tic;
	b=erf(a);
	result=result+toc;
end
res=[res ; result];
fprintf('Erf function over a 1500x1500 matrix (10 times)______: %g sec.\n',result)

% Linear regression over a 2000x2000 matrix
clear a;
clear b;
a=randn(2000,2000);
b=1:2000;
tic;
b=a\b';
result=toc;
res=[res ; result];
fprintf('Linear regression over a 2000x2000 matrix____________: %g sec.\n',result)

% Save results to a file
fid = fopen(filename,'w');
fprintf(fid,'%.3f\n',res);
fclose(fid);

% Display total
fprintf('\nTotal time = %gs\n',sum(res))