https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83262
Bug ID: 83262 Summary: SELECT CASE slower than IF/ELSE Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: tkoenig at gcc dot gnu.org Target Milestone: --- Created attachment 42781 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42781&action=edit Test case with timings The following test case by Tran Quoc Viet from comp.lang.fortran run with the arguments $ ./a.out 100000000 200000000 300000000 compiled with -O3 shows that the Fortran's select case statement is slower by a factor of 1.33 vs. an if/else form. Number of input arguments: 3 GOTO: n =100000000, ss =-0.1480800E+10, time = 0.347 (s) SELECT CASE: n =100000000, ss =-0.1480800E+10, time = 0.199 (s) IF-Goto: n =100000000, ss =-0.1480800E+10, time = 0.151 (s) IF-noGoto: n =100000000, ss =-0.1480800E+10, time = 0.151 (s) IF-ELSE: n =100000000, ss =-0.1480800E+10, time = 0.151 (s) GOTO: n =200000000, ss =-0.2961600E+10, time = 0.702 (s) SELECT CASE: n =200000000, ss =-0.2961600E+10, time = 0.401 (s) IF-Goto: n =200000000, ss =-0.2961600E+10, time = 0.301 (s) IF-noGoto: n =200000000, ss =-0.2961600E+10, time = 0.301 (s) IF-ELSE: n =200000000, ss =-0.2961600E+10, time = 0.301 (s) GOTO: n =300000000, ss =-0.4442400E+10, time = 1.054 (s) SELECT CASE: n =300000000, ss =-0.4442400E+10, time = 0.602 (s) IF-Goto: n =300000000, ss =-0.4442400E+10, time = 0.451 (s) IF-noGoto: n =300000000, ss =-0.4442400E+10, time = 0.452 (s) IF-ELSE: n =300000000, ss =-0.4442400E+10, time = 0.451 (s) GOTO costs totally 2.103 (s) SELECT CASE costs totally 1.202 (s) IF-Goto costs totally 0.903 (s) IF-noGoto costs totally 0.903 (s) IF-ELSE costs totally 0.903 (s) The Fortran FE translates the SELECT CASE into a switch.