|
Boost : |
Subject: Re: [boost] [any] new version
From: Martin Bidlingmaier (Martin.Bidlingmaier_at_[hidden])
Date: 2011-09-01 11:09:01
Mathias Gaunard wrote:
> Ok, so we'll assume that it works on most compilers.
>
> Now why is that better than using the standard mechanism to do this,
> apart from removing the requirement of having RTTI enabled?
>
Performance of any_cast. In the current version of any, it looks something like this:
if( content && content->type() == typeid( T ) )
return static_cast< ... >( content );
else
return 0;
Performancewise, it has to do the following:
- check the content pointer for NULL
- call virtual function type()
- compare type_information
Especially the latter is on the platforms I tested extremely slow.
This is the proposed version:
if( id == type_id< T >::value )
return static_cast< ... >( content );
else
return 0;
, where id is an unsigned int member variable of any.
It's just an integer comparison.
I've done very simple tests on gcc and vc++2010 with std::clock,
and my version took about 75% less ticks than the old version on gcc
and 99.8% (!) less on vc++ (I think this happened because of compiler
optimizations in my special test case). I know the tests I ran were not
nearly professional or accurate, but the trend is clear I guess. Testing performance is something I'm completely unexperienced with, that's why I asked for help there.
In addition to changing the performance of any_cast, I added move constructors (at least on gcc), which will hopefully increase move performance.
On the other hand, sizeof( any ) is now 8, not 4 ( 16/8, depending on architecture) so I suppose copying will be a little bit slower.
-- NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie! Jetzt informieren: http://www.gmx.net/de/go/freephone
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk