Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2005-02-10 17:41:10


From: christopher diggins <cdiggins_at_[hidden]>
> From: "Rob Stewart" <stewart_at_[hidden]>
> >>
> > A better scheme would be to provide a null profiler class that
> > BOOST_PROFILE_START instantiates when BOOST_PROFILE_OFF is
> > defined. Then, there can be empty, inline member functions so
> > that the following code compiles away to nothing in optimized
> > builds:
> >
> > void f()
> > {
> > BOOST_PROFILER(type) prof;
> > // code to profile
> > prof.pause();
> > // code to ignore
> > prof.continue();
> > // more code to profile
> > }
>
> I like this. What if we took it a step further and wrote something like:
>
> template<typename T1, typename T2>
> struct profiler : if_<profiling_on, basic_profiler<T1, T2>,
> null_profiler>::type { };
>
> This would entirely remove the need for macros. What do you think?

Yes, that's good. You'd still probably want to use a macro to
enable/disable profiling so that it can be managed from the
compiler command line. Thus, if the macro is defined,
profiling_on is defined appropriately to select basic_profiler.

The only question is how well that optimizes to nothing in
various compilers.

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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