Constructor Optimization

Allan Sandfeld Jensen kde-optimize@mail.kde.org
Wed, 22 Jan 2003 12:14:15 +0100


On Tuesday 21 January 2003 16:47, Benjamin Meyer wrote:
> I was curius if GCC/G++ would optimize foo = x down to foo(x) if the
> constructor existed so I wrote a small program to time the two.  Now of
> course the time savings couldn't be much, but a wide scale fix/change could
> probably help, especially in applications that constently generate/remove
> new variables.
>
> Here was my result:
> v("x") is faster then v = "x": 24microseconds
>
> This was compiled with:
> g++ -c -pipe -DQWS -fno-exceptions -fno-rtti -Wall -W -O2
> -fno-default-inline -DNO_DEBUG
>
> Is this wrong?
>
In gcc 2.95 you need to add -felide-constructors. In 3.2 it should be default. 
Maybe it doesnt work when you disable inlining of constructors.

`Allan