help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A faster sum


From: Mike Miller
Subject: Re: A faster sum
Date: Sat, 21 May 2005 10:56:20 -0500 (CDT)

On Sat, 21 May 2005, Keith Goodman wrote:

On 5/21/05, Victor Eijkhout <address@hidden> wrote:
You're replacing n^2 operations by n^3. Those operations run faster,
but there are many more of them.

So in theory the relative speedup decreases as the matrix size increases? That's not what I get in practice. For a 1000x1000 matrix the multiplication method is about 3 times faster. For a 5000x5000 matrix it's about 8 times faster.


On an old Octave version, the ones method is just a tad slower:

GNU Octave, version 2.0.14 (sparc-sun-solaris2.6).

octave:1> t=cputime; sum(rand(500,500)); cputime-t
ans = 1.4200
octave:2> t=cputime; ones(1,500)*rand(500,500); cputime-t
ans = 1.4500


On a newer Octave version (but not the newest), thoe ones method is just a tad faster:

GNU Octave, version 2.1.50 (i686-pc-linux-gnu).

octave:119> t=cputime; sum(rand(2000,2000)); cputime-t
ans = 0.90000
octave:121> t=cputime; ones(1,2000)*rand(2000,2000); cputime-t
ans = 0.86000


I get the argument about n^2 and n^3, but it looks like I'm seeing n^2 in both cases. It's as if multiplying by 1 is free. I see that the ones method does just a little bit better than sum on my Octave installation:


GNU Octave, version 2.1.50 (i686-pc-linux-gnu).

octave:124> t=cputime; N=1000; ones(1,N)*rand(N,N); cputime-t
ans = 0.22000
octave:125> t=cputime; N=2000; ones(1,N)*rand(N,N); cputime-t
ans = 0.86000
octave:126> t=cputime; N=3000; ones(1,N)*rand(N,N); cputime-t
ans = 1.9400
octave:127> t=cputime; N=4000; ones(1,N)*rand(N,N); cputime-t
ans = 3.4600
octave:128> t=cputime; N=5000; ones(1,N)*rand(N,N); cputime-t
ans = 5.4000

octave:129> t=cputime; N=1000; sum(rand(N,N)); cputime-t
ans = 0.23000
octave:130> t=cputime; N=2000; sum(rand(N,N)); cputime-t
ans = 0.91000
octave:131> t=cputime; N=3000; sum(rand(N,N)); cputime-t
ans = 2.0700
octave:132> t=cputime; N=4000; sum(rand(N,N)); cputime-t
ans = 3.6400
octave:133> t=cputime; N=5000; sum(rand(N,N)); cputime-t
ans = 5.6300


Best,

Mike



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

[Prev in Thread] Current Thread [Next in Thread]