[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Octave interpreter slowness
From: |
John Swensen |
Subject: |
Re: Octave interpreter slowness |
Date: |
Wed, 15 Mar 2006 15:58:05 -0700 |
User-agent: |
Thunderbird 1.4.1 (Windows/20051006) |
Keith Goodman wrote:
> On 3/15/06, John Swensen <address@hidden> wrote:
>
>> In some recent work, I wasn't able to get our companies' only Matlab
>> Statistics toolbox license, so I switched to octave for a week or two.
>> I noticed that the poisson random function in octave took orders of
>> magnitude longer than Matlab's implementation. This led me to do a
>> simple experiment. I ran the following script on the same computer with
>> both Matlab and Octave (WinXP with Cygwin Octave release vs. Matlab
>> 7.something), with very interesting results.
>> -------------------------------
>> tic
>> size = 1000000;
>> var = zeros(1,size);
>> for i = 1:size
>> var(i) = rand();
>> end
>> sum(var)
>> ElapsedTime = toc
>> -------------------------------
>>
>> Matlab (10 runs) - Ave = 2.0818 seconds
>> Octave (10 runs) - Ave = 19.911 seconds
>>
>> Since this is a fairly simple script with a lot of iterations, does this
>> indicate that the discrepency is caused somewhere in the parsing
>> portions of Octave? I tried the test again with the rand() call
>> eliminated with similar differences in execution times. I then tried
>> the script in Octave on a faster PC running Ubuntu with some
>> improvements (15 seconds per).
>>
>
> For loops are slow in Octave.
>
> When most of the time of a single for loop iteration is spent in
> matrix operations, the slowness of the for looping is not noticeable.
> But when most of the time is spent in looping, it is very noticeable.
>
> For example
>
> a = randn(N);
> tic
> for i = 1:1000
> x = a*a';
> end
> toc
>
> As you increase N, the ratio of the slowness decreases.
>
> If N is small, the trick is either to vectorize or compile your
> function with mkoctfile.
>
>
>
I guess my question pertains as to the source of the slowness. Is it
the parser, or is Matlab doing some sort of look-ahead optimization of m
files? Do they compile to byte-code or something similar prior to
execution?
-John Swensen
-------------------------------------------------------------
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
-------------------------------------------------------------