Boost logo

Boost :

Subject: Re: [boost] [local] Help for the Alternatives section
From: Vicente BOTET (vicente.botet_at_[hidden])
Date: 2011-03-29 01:43:10


> Message du 28/03/11 19:52
> De : "lcaminiti"
> A : boost_at_[hidden]
> Copie à :
> Objet : Re: [boost] [local] Help for the Alternatives section
>
>
> Thomas Heller-7 wrote:
> >
> > On Monday, March 28, 2011 07:03:46 PM lcaminiti wrote:
> > >
> > > Thomas Heller-7 wrote:
> > > >
> > > > On Monday, March 28, 2011 05:25:13 AM Jeremy Maitin-Shepard
> > wrote:
> > > > > On 03/26/2011 03:19 PM, Lorenzo Caminiti wrote:
> > > > > > Hello all,
> > > > > >
> > > > > > I am updating Boost.Local docs and I could use
> > a some help in
> > > > getting
> > > > > > the Alternatives section right
> > > > > >
> > > >
> > http://svn.boost.org/svn/boost/sandbox/local/libs/local/doc/html/boost_local/Alternatives.html
> > > > >
> > > > > You might include compile time and run time benchmarks,
> > information
> > > > > about error message quality, and polymorphic
> > capabilities.
> > > > > Additionally, you might note that with C++0x local
> > classes can be
> > > > used
> > > > > with templates.
> > > >
> > > > Just did a quick test ... code is attached ...
> > > >
> > > > $ time g++ -O3 -I. -Wall -Wextra add.cpp -o add
> > > >
> > > > real 0m0.657s
> > > > user 0m0.583s
> > > > sys 0m0.067s
> > > >
> > > > $ time ./add
> > > > 1e+12
> > > >
> > > > real 0m35.641s
> > > > user 0m35.618s
> > > > sys 0m0.017s
> > > >
> > > > $ time g++ -O3 -I. -Wall -Wextra add_boost_phoenix.cpp -o
> > add_phoenix
> > > >
> > > > real 0m3.385s
> > > > user 0m3.160s
> > > > sys 0m0.217s
> > > > thomas_at_sunshine ~/programming/local $ time ./add_phoenix
> > > > 1e+12
> > > >
> > > > real 0m6.648s
> > > > user 0m6.643s
> > > > sys 0m0.007s
> > > >
> > >
> > > This is not a fare comparison because add.cpp contains also local
> > blocks and
> > > exits while add_boost_phoenix.cpp contains only local functions. The
> > > comparison should be made between add_boost_local.cpp and
> > > add_boost_phoenix.cpp (see below). The example names got a bit
> > confusing and
> > > I will rename add.cpp to add_funciton_block_exit.cpp to avoid similar
> > > misunderstandings in the future.
> >
> > Seriously? Did you even look at the files i attached?
> >
>
> Ooops... no, I didn't. I have files with the exact same name in
> sandbox/local/libs/local/examples so I assumed you attached these files...
>
>
>
> > Are you serious? Please write real benchmarks. By executing the resulting
> > binaries of your code examples, the runtime is mainly dominated by process
> > setup
> > and the output on stdout.
> >
> > Take a look here:
> > https://svn.boost.org/svn/boost/trunk/libs/spirit/optimization/
> >
>
> I have looked at the files you have attached now and I see what you mean.
> Please scratch my previous benchmark numbers. I will run correct tests more
> along the lines of what you suggested.

Hi Lorenzo,

To complete the performance comparison I will add a hand written test which should be used as reference implementation.

for (size_t i = 0; i < v.size(); ++i) {
sum += factor * num;
}

and a non-local functor so it can be used with foreach (which seems to perform better than the manual for (size_t i = 0; i < v.size(); ++i)

struct non_local_add {
// Unfortunately, extra code to manually program the functor class.
local_add(double& _sum, int _factor): sum(_sum), factor(_factor) {}

void operator()(double num) {
// Body uses C++ statement syntax.
sum += factor * num;
std::cout << "Summed: " << sum << std::endl;
}

private:
// Unfortunately, cannot bind so repeat variable types.
double& sum; // Access `sum` by (non-constant) reference.
const int factor; // Make `factor` constant.
} ;

int main() {
double sum = 0.0;
int factor = 10;

std::vector v(3);
v[0] = 1.0; v[1] = 2.0; v[2] = 3.0;

non_local_add add(sum, factor);

// Non Local functor `add` passed as template parameter.
std::for_each(v.begin(), v.end(), add);

std::cout << sum << std::endl;
return 0;
}

In addition you can use Boost.Chrono so you measure exactly what you want to measure,i.e. the add instantiation + the foreach without setup and output.

Best,
Vicente

P.S. I see that others have the same issue I have when posting in this list with the '<' and '>' symbols. From where you sent your last messages that results in html codes?


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk