discuss-gnuradio
[Top][All Lists]
Advanced

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

Re: [Discuss-gnuradio] ANCI-C vs Gnuradio/C++ speeeed


From: Achilleas Anastasopoulos
Subject: Re: [Discuss-gnuradio] ANCI-C vs Gnuradio/C++ speeeed
Date: Sat, 13 May 2006 12:39:54 -0400
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Al,

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 howto_viterbi_X.cc
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,
Achilleas




-------------------

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)




reply via email to

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