Re: How to compare two algorithms in MATLAB
- From: "hollowspook" <hollowspook@xxxxxxxxx>
- Date: 31 Mar 2007 06:28:02 -0700
yep, I know why flops function is obsolete. However If I really want
to compare two algorithms, can I use the following process?
1. Program them in a Compiled Language like Fortran, C++,....
2. Run the program on same machine
3. Compare the CPU time they take and the memory they need .
Or is there better practical method?
Sam
On 3月31日, 下午6时54分, "John D'Errico" <woodch...@xxxxxxxxxxxxxxxx> wrote:
Konstantinos Konstantinidis wrote:
I think the fellow means if you can do it automatically in Matlab.
I
actually had the same problem since R12 so i had to do everything
by hand.
Is there actually some way to count operations in Matlab? I found a
program
that counts flops but that is outside matlab and surely conciders
some
background programs and windows as well, so it is not objective.
Flops was really nice...
All would be good if flops actually
was correct. It is no longer applicable.
Its not just that they capriciously
decided to make your life miserable.
For example, do you KNOW how many
flops are involved in a single
matrix multiply? Do you KNOW it?
Are you sure? Try out the following
code. While it is executing, do NOT
even touch your mouse. If you have a
fast computer, allow N to go a little
larger.
figure
N = (5:250)';
t = zeros(length(N),2);
M = 20;
for i = 1:length(N)
A = rand(N(i));
B = rand(N(i));
for L = 1:2
tic;
for j = 1:M
C = A*B;
end
t(i,L) = toc;
end
end
loglog(N,t,'-o')
grid on
Note that the plot produced should
be linear. There should not be any
repeatable dips, bumps, jiggles. Yet
there will be exactly that.
These intriguing artifacts will be
repeatable. Note that there are two
curves plotted. If you run it again,
the same bumps appear. There are even
dips, where increasing the size of the
matrices causes a significant decrease
in the time required.
Worse, this behavior will vary depending
on what cpu you have, how much ram you
have, how large are the various caches
your cpu has, etc. I can't even imagine
what effect a multi-threaded blas call
does to this mess.
This behavior cannot be predicted by
the simple O(N^3) theoretical number
for the flops count.
THERE IS A REASON WHY THEY DROPPED
FLOPS.
John
.
- Follow-Ups:
- Re: How to compare two algorithms in MATLAB
- From: John D'Errico
- Re: How to compare two algorithms in MATLAB
- References:
- How to compare two algorithms in MATLAB
- From: hollowspook
- Re: How to compare two algorithms in MATLAB
- From: Nasser Abbasi
- Re: How to compare two algorithms in MATLAB
- From: Konstantinos Konstantinidis
- Re: How to compare two algorithms in MATLAB
- From: John D'Errico
- How to compare two algorithms in MATLAB
- Prev by Date: Re: title and sprintf (command in plot)
- Next by Date: Re: Inverse Hough Transform
- Previous by thread: Re: How to compare two algorithms in MATLAB
- Next by thread: Re: How to compare two algorithms in MATLAB
- Index(es):
Relevant Pages
|