Re: ANCI-C vs Gnuradio/C++ speeeed


thanks for pointing out this mistake.
I changed this in the code.
I guess when I was using ANSI-C I was forced
to use pointer etc, but with C++ it is
easy to fall in to these traps.

Anyway, as I said to my previous post,
this does not contribute anything noticable to the
speed reduction, as most of the action is happening in
the file
and in particular in the function
void viterbi_algorithm(const int I, const int S, const int O,
const std::vector &NS,
const std::vector &OS,
const std::vector &PS,
const std::vector &PI,
const int K,
const int S0,const int SK,
const float *in, @TYPE@ *out,
std::vector &trace)

Thanks again,

On Friday 12 May 2006 18:34, al davis wrote:

You are returning a vector by value:
from fsm.h:
std::vector NS () const { return d_NS; }
std::vector OS () const { return d_OS; }
std::vector PS () const { return d_PS; }
std::vector PI () const { return d_PI; }

Returning by value means that the copy constructor is invoked to
make the copy. It is in the .cc file, forcing it to be
explicitly called, complete with stack frame overhead, but this
is not what is important. Copying a vector is done by a loop,
so it is an O(n) operation.

To return by reference, add a &…
std::vector & PI () const { return d_PI; }

Now it won’t make a copy, but the vector is modifyable. You
might want:
const std::vector & PI () const { return d_PI; }
to protect it.

A double nested loop takes time O(n2). By putting O(n)