Boost logo

Boost :

From: Noah Roberts (roberts.noah_at_[hidden])
Date: 2007-01-27 11:16:33


Matthias Schabel wrote:
>> hmmm...decided to try and test this guy out and based on the docs I
>> would think the following code would compile, but it doesn't in VC++
>> 8.0...g++ gobbles it up ok though.
>
> A better fix is to replace the code between the #ifdef
> MCS_HAS_TYPEOF ... #endif // MCS_HAS_TYPEOF with the following:

Ok, I probably won't get to do this until Friday again...that's the day
I get to work on personal things at work for a few hours...I don't have VC.

I was profiling my own version and it was dog slow compared to doubles.
 I wanted to check yours. I did here at home with g++ on Linux and our
two versions compare equally wrt the static dim quantity. I had to
really vamp up the optimizations of course to get them as fast as
doubles (I couldn't find the right options for VC) and I still can't do
as deep a recursion level without a seg fault...this is actually by
quite a margin...several orders of magnitude. Both versions fail at the
same point. Here is test code...add a 0 to the end of tlim and I get a
crash on the quantity version:

#include <boost/units/io.hpp>
#include <boost/units/systems/si_units.hpp>

int const tlim = 50000;

double f_dbl(double x, double y, double z, int count)
{
  static double const C = 3.14;

  if (!count) return 0;

  return ((x + y) * z * C) + f_dbl(x, y, z, count - 1);
}

using namespace boost::units;
using namespace boost::units::SI;

quantity<volume> f_qty(quantity<length> x, quantity<length> y,
quantity<length> z, int count)
{
  static quantity<length> const C = 3.14 * meters;

  if (!count) return 0 * cubic_meters;

  return ((x + y) * z * C) + f_qty(x, y, z, count - 1);
}

#include <iostream>
int main()
{
  std::cout << f_dbl(1,2,3,tlim) << std::endl;
  std::cout << f_qty(1 * meters, 2 * meters, 3 * meters, tlim) << std::endl;
}

COMMAND LINE:

nroberts_at_localhost ~/projects/prof_units $ g++ -I/home/nroberts/units
-pg -O3 prof_mcs.cpp

This is likely implementation dependant and maybe there's still more ops.


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