Forum: GNU Radio Re: ANCI-C vs Gnuradio/C++ speeeed

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Achilleas A. (Guest)
on 2006-05-13 20:42
(Received via mailing list)

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<int> &NS,
              const std::vector<int> &OS,
              const std::vector<int> &PS,
              const std::vector<int> &PI,
              const int K,
              const int S0,const int SK,
              const float *in, @TYPE@ *out,
              std::vector<int> &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<int> NS () const { return d_NS; }
 >>   std::vector<int> OS () const { return d_OS; }
 >>   std::vector<int> PS () const { return d_PS; }
 >>   std::vector<int> 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<int> & PI () const { return d_PI; }

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

A double nested loop takes time O(n2).  By putting O(n)
This topic is locked and can not be replied to.