I have two derived types (child1 and child2) that both extend from the same abstract type (type, abstract :: parent
). The abstract type has a deferred bound procedure.
I want to call a subroutine that performs some stuff (performance critical) depending on the type of the child handed over as input. I can think of two options:
- The subroutine takes the
class(parent), intent(inout) :: type_in
as input. Implementations for the children are then done within aselect type (type_in)
construct. - I write two subroutines, one with
type(child1), intent(inout) :: type_in
and one withtype(child2), intent(inout) :: type_in
and provide an explicit interface to overload the routine name.
The first option allows for implementations where the extension of the parent is not known at compile time, but that is not necessary in my case. It also saves some lines of code because only a part of it is different for the children.
My question is: Is there additional overhead in option one because I implemented the input as polymorphic data when the type is known at compile time?