Boost logo

Boost Users :

Subject: Re: [Boost-users] boost variant compile time visitation: verification
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-04-21 10:09:55


Following my prev message, I wrote the following test on a win platform,
compiled with VS2005 /O2 in release mode

#include <iostream>
#include <boost/variant/variant.hpp>
#include <windows.h>

typedef boost::variant<int, double, char> VT;

struct print_type : public boost::static_visitor<const char*> {
  const char* operator()( int )
  {
    return "int";
  }
  const char* operator()( double )
  {
    return "double";
  }
  const char* operator()( char )
  {
    return "char";
  }
};

int main()
{
  const VT v('c');
  LARGE_INTEGER usec0, usec1;
  const char* volatile res;
  
  QueryPerformanceCounter( &usec0 );
  for(size_t s=0; s<2000000; ++s)
    res = v.apply_visitor( print_type() );
  QueryPerformanceCounter( &usec1 );
  std::cout<< (usec1.QuadPart - usec0.QuadPart) <<std::endl;
 
  QueryPerformanceCounter( &usec0 );
  for(size_t s=0; s<2000000; ++s)
    res = "char";
  QueryPerformanceCounter( &usec1 );
  std::cout<< (usec1.QuadPart - usec0.QuadPart) <<std::endl;
}

There is no statistically significant difference between the 2 cases.

Can I deduce that at least on this platform, for this code, the visitation
is done at compile-time?

Rds,


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net