compare the executive speed with Matlab

John W. Eaton jwe at octave.org
Fri Jan 2 13:45:17 CST 2009


On  2-Jan-2009, Jordi Gutiérrez Hermoso wrote:

| It's quite easy to come up with this example. In fact, he more or less
| gave the example.

No, he described the example.  I usually want to see precisely what
the code is that someone is talking about, and I don't want to have to
guess about what that might be.

| He's talked about this example before in the mailing list too.

Then provide a URL for a previous discussion.  Don't assume we can
find previous discussion by searching the web.  We may find something
different from what the OP had in mind.  It helps if we know we are
discussing the same thing, without having to guess.

| In Octave,
| 
|      octave:1> v = [1:15e6];
|      octave:2> tic, sin(v); toc;
|      Elapsed time is 1.39321 seconds.

If you want to do comparisons, please use cputime instead of tic/toc.
That way, you can get the user and system CPU time.  The wall clock
time that tic/toc returns is not very useful for comparison purposes.
There could have been other things running on your system when this
code was executed.

| 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.

Some things I can think of:

  Octave has to include a call to the OCTAVE_QUIT macro inside the
  loop, so that the loop can be interrupted.

  There is some overhead for setting up a function call in Octave.

  Space for the result vector must be allocated, and elements of the
  argument vector must referenced.

jwe



More information about the Help-octave mailing list