Boost logo

Boost :

Subject: Re: [boost] [convert] Performance
From: Vladimir Batov (Vladimir.Batov_at_[hidden])
Date: 2014-06-10 19:17:59

On 06/11/2014 06:55 AM, Andrey Semashev wrote:
> On Wednesday 11 June 2014 06:46:53 Vladimir Batov wrote:
>> And indeed BOOST_ASSERT seems to be heavier than BOOST_TEST due to
>> expression-validity check done with
>> __builtin_expect(expr, 1)
> It's not a validity check, it's a hint to the compiler to help branch
> prediction. Assertion failures are assumed to be improbable.
> In any case, when testing performance you should be building in release mode,
> where all asserts are removed.

Yes, indeed, Andrey, thank you. What I was referring to was:

#define BOOST_TEST(expr) ((expr)? (void)0:
::boost::detail::test_failed_impl(#expr, __FILE__, __LINE__,

#define BOOST_ASSERT(expr) (BOOST_LIKELY(!!(expr)) \
   ? ((void)0) \
   : ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__,

#define BOOST_LIKELY(x) __builtin_expect(x, 1)

That is, BOOST_TEST simply tests (expr) when BOOST_ASSERT tests with
!!__builtin_expect(expr, 1). That said, you are absolutely correct that
the actual validity test is with !! rather than __builtin_expect as I
ignorantly expressed it. Thank you.

Boost list run by bdawes at, gregod at, cpdaniel at, john at