help-octave
[Top][All Lists]
Advanced

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

oct file: slower than expected using fortran_vec


From: Seb Astien
Subject: oct file: slower than expected using fortran_vec
Date: Sun, 15 May 2011 22:10:51 +0200

Hi,

I have been experimenting a bit with oct files to see how much faster
it would be.
I wrote a trivial example to sum the elements of an array.
To my surprised, this was still much slower than built-in functions:

octave:1> A=rand(10000,10000);
octave:2> tic; s1=sum(sum(A)); toc
Elapsed time is 0.222649 seconds.
octave:3> tic; s2=sumit(A); toc
Elapsed time is 1.5032 seconds.

The C++ code is below. I added a const in front of *p to prevent
copying, but I guess it is still happening.

Any comment, pointer, explanation would be greatly appreciated.

Regards,

Seb

===
#include <octave/oct.h>

DEFUN_DLD (sumit, args, , "Sum elements of an array")
{
        int nargin = args.length();
        
        if (nargin != 1){
                print_usage();
                return octave_value_list();
        }
        
        NDArray A = args(0).array_value();
        const double *p = A.fortran_vec();
        double sum = 0;
        octave_idx_type N = args(0).nelem();
        
        if (! error_state){
                for(octave_idx_type i=0; i<N; i++)
                        sum += *(p++);
                return octave_value (sum);
        }
}
===


reply via email to

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