Code covered by the BSD License  

Highlights from
Performance in object-oriented matlab code

image thumbnail

Performance in object-oriented matlab code

by

 

16 Apr 2013 (Updated )

A very simple example to demonstrate an observation of mine regarding the use of classes in matlab.

PerfTest.m
% Written by Dimitrios Korkinof
% Imperial College London
% http://www.korkinof.com

clear all;

N = 200;

mat = zeros(N,N);

c1 = C1(N);
c2 = C2(N);
c1_h = C1_h(N);
c2_h = C2_h(N);
f = F(N);

tic;
for i=1:N
    for j=1:N
        mat(i,j) = rand(1,1);
    end
end
time.core = toc;

tic;
for i=1:N
    for j=1:N
        c1 = modify_one(c1,i,j);
    end
end
time.c1 = toc;

tic;
for i=1:N
    for j=1:N
        c2 = modify_one(c2);
    end
end
time.c2 = toc;

tic;
for i=1:N
    for j=1:N
        c1_h = modify_one(c1_h,i,j);
    end
end
time.c1_h = toc;

tic;
for i=1:N
    for j=1:N
        c2_h = modify_one(c2_h);
    end
end
time.c2_h = toc;

tic;
for i=1:N
    for j=1:N
        f.modify_one(i,j);
    end
end
time.f = toc;


time

overhead(1,:) = [time.core,time.c1-time.core];
overhead(2,:) = [time.core,time.c2-time.core];
overhead(3,:) = [time.core,time.c1_h-time.core];
overhead(4,:) = [time.core,time.c2_h-time.core];
overhead(5,:) = [time.core,time.f-time.core];


h = bar(overhead,'stacked');
colormap(1-cool);

Contact us