Quantcast
Channel: Последние публикации
Viewing all articles
Browse latest Browse all 11

Speed of case block

$
0
0

Hello!

I ask you to help me with the understanding of the issue on speed of code. I have the following code:

integer, parameter :: EL_H = 1
02	integer, parameter :: EL_He = 2
03	integer, parameter :: EL_Li = 3
04	integer, parameter :: EL_Be = 4
05	integer, parameter :: EL_B = 5
06	integer, parameter :: EL_C = 6
07	integer, parameter :: EL_N = 7
08	integer, parameter :: EL_O = 8
09	integer, parameter :: EL_F = 9
10
11	real, parameter ::  MolarMass(9) = (/ 1.0079, 4.0026, 6.941, 9.01218, 10.81, &
                                                                12.011, 14.0067, 15.9994,18.9984/)
12
13	contains
14
15	elemental subroutine GetMolarMass(EL, MM)
16	  integer, intent(in) :: EL
17	  real, intent(out) :: MM
18	  select case( EL)
19	    case(EL_H ) ; MM = 1.0079
20	    case(EL_He) ; MM = 4.0026
21	    case(EL_Li) ; MM = 6.941
22	    case(EL_Be) ; MM = 9.01218
23	    case(EL_B ) ; MM = 10.81
24	    case(EL_C ) ; MM = 12.011
25	    case(EL_N ) ; MM = 14.0067
26	    case(EL_O ) ; MM = 15.9994
27	    case(EL_F ) ; MM = 18.9984
28	  end select
29	end subroutine

This code provides two opportunities to get the molar mass of elements - through the array and through the routine. I have 2 questions:

1) providing a molar mass through routine will be slower?

2) It is known that the speed of access to an element of the array is independent of its size. So increasing the number of elements and the size of the array MolarMass will not affect the speed of access to an element. But will increasing the number of elements (and so increasing the number of  cases in case block)  slow the speed of the subroutine GetMolarMass? In other words: is the speed of case block independent of number of cases or not?


Viewing all articles
Browse latest Browse all 11

Latest Images

Trending Articles





Latest Images