[Insight-developers] assert and explicit instantiations
Luis Ibanez
luis.ibanez at kitware.com
Mon Jun 15 12:14:28 EDT 2009
Hi Gaetan,
Yes, I see your point.
Adding more conditions in the operator++() will degrade performance.
Just to clarify here,
The penalty in performance will come from the extra "if" that
guards that call to the Exception, not from the actual Exception.
Exceptions themselves will only be thrown when there is an error,
and in that case, performance is no longer an issue. That is, Exceptions
will not make part of the normal flow of the code.
The effect of the "if" may be not be that significant,
given that the current code in the operator++() calls Next()
which is a virtual function.
Self & operator++()
{
this->Next();
return *this;
}
That said, I fully agree with you in that before taking such
route we should profile the impact on performance.
Going with pure asserts, as you suggest, seems to be a more
reasonable approach.
Luis
--------------------
Gaëtan Lehmann wrote:
>
> Le 14 juin 09 à 18:43, Luis Ibanez a écrit :
>
>>
>>
>> Hi Gaetan,
>>
>
> Hi Luis,
>
>> You should probably use the new Macro:
>>
>> itkAssertOrThrowMacro
>>
>>
>> That is defined in
>>
>> Insight/Code/Common/itkMacro.h
>>
>>
>> It will use Asserts when compiled in Debug mode,
>> and it will throw Exceptions when compiled in
>> Release mode.
>
>
> Well, we should carefully use that macro, because exceptions can have
> serious impact on performance.
> In that case, the assert() is in operator++() and Set() methods of an
> iterator.
>
>
> http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkTreeIteratorBase.h?root=Insight&r1=1.12&r2=1.13&sortby=date
>
>
> http://public.kitware.com/cgi-bin/viewcvs.cgi/Code/Common/itkTreeIteratorBase.txx?root=Insight&r1=1.14&r2=1.15&sortby=date
>
>
> This is the kind of case where I wouldn't replace an assert() by
> itkAssertOrThrowMacro(), or at least without carefully measuring the
> execution times.
>
> Regards,
>
> Gaëtan
>
>>
>>
>>
>> Luis
>>
>>
>> -----------------------
>> Gaëtan Lehmann wrote:
>>
>>> Hi Julien,
>>> I have commented an assert() in
>>> Code/Common/itkTreeIteratorBase.h
>>> Code/Common/itkTreeIteratorBase.h
>>> to fix build with explicit instantiation.
>>> The compiler was giving that error:
>>> /export/home/glehmann/src/Insight/Code/Common/ itkTreeIteratorBase.h:
>>> 182: erreur: ‘assert’ was not declared in this scope
>>> Is it the expected behavior?
>>> Thans,
>>> Gaëtan
>>> ------------------------------------------------------------------------
>>> _______________________________________________
>>> Powered by www.kitware.com
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-developers
>
>
More information about the Insight-developers
mailing list