- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have a select case with maybe 400 cases. I have coded it into groups because I wanted to group selections belonging to function. Here is a simplification:
When I step through this in the VS debugger I notice that the top level select jumps around checking each case in turn until it finds one that matches, but the lower level one with single items in the cases jumps straight to the selection. It seams like a completly different approach it taken for the two cases and I was wondering if the multi-item (top level) selection has a penalty in speed?
Maybe I should do the top level differently like:
[bash]select case(i) case (0:99) call selectFirst100(i) case(100:199) call select100To200(i) case((200:299) call select200To300(i) case((300:399) call select300To300(i) end select subroutine selectFirst100(i) integer, intent(in) :: i select case(i) case(1) !Do something case(2) !ETC end select end subroutine[/bash]
When I step through this in the VS debugger I notice that the top level select jumps around checking each case in turn until it finds one that matches, but the lower level one with single items in the cases jumps straight to the selection. It seams like a completly different approach it taken for the two cases and I was wondering if the multi-item (top level) selection has a penalty in speed?
Maybe I should do the top level differently like:
[bash]if (i > -1 .and. i < 100) then call selectFirst100(i) else if (i < 200) then call select100To200(i) else if (i < 300) then call select200To300(i) else if (i < 400) then call select300To400(i) end if[/bash]
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The compiler does optimize simpler SELECT CASE constructs, but when there is a range, it reverts to a series of comparisons just like your replacement code. I suggest leaving the outer one as it is. Or you might do something like having the outer one select on i/100 with values of 0, 1, 2, etc. That would probably get optimized.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page