compare the executive speed with Matlab
Jordi Gutiérrez Hermoso
jordigh at gmail.com
Fri Jan 2 13:21:20 CST 2009
2009/1/2 John W. Eaton <jwe at octave.org>:
> On 2-Jan-2009, Sergei Steshenko wrote:
>
> | Well, IIRC, if I need to calculate, say, 'sin' function for a vector of
> | ~150000 elements, 'octave' speed is ~5 times slower than the one of the
> | equivalent code in "C".
>
> How about posting an actual working example so we can see exactly what
> it is you are comparing? Perhaps you are doing something stupid, and
> your comparison is not valid. Or perahaps there is a good reason that
> Octave must do extra work compared to the C version.
It's quite easy to come up with this example. In fact, he more or less
gave the example. He's talked about this example before in the mailing
list too.
In Octave,
octave:1> v = [1:15e6];
octave:2> tic, sin(v); toc;
Elapsed time is 1.39321 seconds.
In C,
#include <math.h>
int main(){
int N = 15000000;
int i;
double d;
for(i = 0; i < N; i++)
d = sin( (double) i);
}
then
jordi at Iris:~$ gcc foo.c -o foo -lm && time foo
real 0m1.035s
user 0m1.024s
sys 0m0.012s
It's not a very noticeable difference, but I do wonder why there is
one at all.
- Jordi G. H.
More information about the Help-octave
mailing list