OK, so I couldn't help myself. I had to see a benchmark NOW apparently (this kind of talk always gets me very interested).
Here's my simple benchmark code:
t0# = Timer()
for i = 1 to 1000000
GoSwitch()
next i
t1# = Timer()
test1_time# = t1# - t0#
for i = 1 to 1000000
GoElseIF()
next i
test2_time# = Timer() - t1#
do
Print("GoSwitch time = " + str(test1_time#))
Print("GoElseIF time = " + str(test2_time#))
sync()
loop
function GoSwitch()
a = 100
select a
case 1:
b = sin(60)
endcase
case 2:
b = sin(60)
endcase
case 3:
b = sin(60)
endcase
case 4:
b = sin(60)
endcase
case 5:
b = sin(60)
endcase
case 6:
b = sin(60)
endcase
case 7:
b = sin(60)
endcase
case 8:
b = sin(60)
endcase
case 9:
b = sin(60)
endcase
case 10:
b = sin(60)
endcase
case 11:
b = sin(60)
endcase
case 12:
b = sin(60)
endcase
case 13:
b = sin(60)
endcase
case 14:
b = sin(60)
endcase
case 15:
b = sin(60)
endcase
case 16:
b = sin(60)
endcase
case 17:
b = sin(60)
endcase
case 18:
b = sin(60)
endcase
case 19:
b = sin(60)
endcase
case 20:
b = sin(60)
endcase
case 21:
b = sin(60)
endcase
case 22:
b = sin(60)
endcase
case 23:
b = sin(60)
endcase
case 24:
b = sin(60)
endcase
case 25:
b = sin(60)
endcase
case 26:
b = sin(60)
endcase
case 27:
b = sin(60)
endcase
case 28:
b = sin(60)
endcase
case 29:
b = sin(60)
endcase
case 30:
b = sin(60)
endcase
case 31:
b = sin(60)
endcase
case 32:
b = sin(60)
endcase
case 33:
b = sin(60)
endcase
case 34:
b = sin(60)
endcase
case 35:
b = sin(60)
endcase
case 36:
b = sin(60)
endcase
case 37:
b = sin(60)
endcase
case 38:
b = sin(60)
endcase
case 39:
b = sin(60)
endcase
case 40:
b = sin(60)
endcase
case 41:
b = sin(60)
endcase
case 42:
b = sin(60)
endcase
case 43:
b = sin(60)
endcase
case 44:
b = sin(60)
endcase
case 45:
b = sin(60)
endcase
case 46:
b = sin(60)
endcase
case 47:
b = sin(60)
endcase
case 48:
b = sin(60)
endcase
case 49:
b = sin(60)
endcase
case 50:
b = sin(60)
endcase
case 51:
b = sin(60)
endcase
case 52:
b = sin(60)
endcase
case 53:
b = sin(60)
endcase
case 54:
b = sin(60)
endcase
case 55:
b = sin(60)
endcase
case 56:
b = sin(60)
endcase
case 57:
b = sin(60)
endcase
case 58:
b = sin(60)
endcase
case 59:
b = sin(60)
endcase
case 60:
b = sin(60)
endcase
case 61:
b = sin(60)
endcase
case 62:
b = sin(60)
endcase
case 63:
b = sin(60)
endcase
case 64:
b = sin(60)
endcase
case 65:
b = sin(60)
endcase
case 66:
b = sin(60)
endcase
case 67:
b = sin(60)
endcase
case 68:
b = sin(60)
endcase
case 69:
b = sin(60)
endcase
case 70:
b = sin(60)
endcase
case 71:
b = sin(60)
endcase
case 72:
b = sin(60)
endcase
case 73:
b = sin(60)
endcase
case 74:
b = sin(60)
endcase
case 75:
b = sin(60)
endcase
case 76:
b = sin(60)
endcase
case 77:
b = sin(60)
endcase
case 78:
b = sin(60)
endcase
case 79:
b = sin(60)
endcase
case 80:
b = sin(60)
endcase
case 81:
b = sin(60)
endcase
case 82:
b = sin(60)
endcase
case 83:
b = sin(60)
endcase
case 84:
b = sin(60)
endcase
case 85:
b = sin(60)
endcase
case 86:
b = sin(60)
endcase
case 87:
b = sin(60)
endcase
case 88:
b = sin(60)
endcase
case 89:
b = sin(60)
endcase
case 90:
b = sin(60)
endcase
case 91:
b = sin(60)
endcase
case 92:
b = sin(60)
endcase
case 93:
b = sin(60)
endcase
case 94:
b = sin(60)
endcase
case 95:
b = sin(60)
endcase
case 96:
b = sin(60)
endcase
case 97:
b = sin(60)
endcase
case 98:
b = sin(60)
endcase
case 99:
b = sin(60)
endcase
case 100:
b = sin(60)
endcase
case default:
b = sin(60)
endcase
endselect
endfunction
function GoElseIf()
a = 100
if a = 1
b = sin(60)
elseif a = 2
b = sin(60)
elseif a = 3
b = sin(60)
elseif a = 4
b = sin(60)
elseif a = 5
b = sin(60)
elseif a = 6
b = sin(60)
elseif a = 7
b = sin(60)
elseif a = 8
b = sin(60)
elseif a = 9
b = sin(60)
elseif a = 10
b = sin(60)
elseif a = 11
b = sin(60)
elseif a = 12
b = sin(60)
elseif a = 13
b = sin(60)
elseif a = 14
b = sin(60)
elseif a = 15
b = sin(60)
elseif a = 16
b = sin(60)
elseif a = 17
b = sin(60)
elseif a = 18
b = sin(60)
elseif a = 19
b = sin(60)
elseif a = 20
b = sin(60)
elseif a = 21
b = sin(60)
elseif a = 22
b = sin(60)
elseif a = 23
b = sin(60)
elseif a = 24
b = sin(60)
elseif a = 25
b = sin(60)
elseif a = 26
b = sin(60)
elseif a = 27
b = sin(60)
elseif a = 28
b = sin(60)
elseif a = 29
b = sin(60)
elseif a = 30
b = sin(60)
elseif a = 31
b = sin(60)
elseif a = 32
b = sin(60)
elseif a = 33
b = sin(60)
elseif a = 34
b = sin(60)
elseif a = 35
b = sin(60)
elseif a = 36
b = sin(60)
elseif a = 37
b = sin(60)
elseif a = 38
b = sin(60)
elseif a = 39
b = sin(60)
elseif a = 40
b = sin(60)
elseif a = 41
b = sin(60)
elseif a = 42
b = sin(60)
elseif a = 43
b = sin(60)
elseif a = 44
b = sin(60)
elseif a = 45
b = sin(60)
elseif a = 46
b = sin(60)
elseif a = 47
b = sin(60)
elseif a = 48
b = sin(60)
elseif a = 49
b = sin(60)
elseif a = 50
b = sin(60)
elseif a = 51
b = sin(60)
elseif a = 52
b = sin(60)
elseif a = 53
b = sin(60)
elseif a = 54
b = sin(60)
elseif a = 55
b = sin(60)
elseif a = 56
b = sin(60)
elseif a = 57
b = sin(60)
elseif a = 58
b = sin(60)
elseif a = 59
b = sin(60)
elseif a = 60
b = sin(60)
elseif a = 61
b = sin(60)
elseif a = 62
b = sin(60)
elseif a = 63
b = sin(60)
elseif a = 64
b = sin(60)
elseif a = 65
b = sin(60)
elseif a = 66
b = sin(60)
elseif a = 67
b = sin(60)
elseif a = 68
b = sin(60)
elseif a = 69
b = sin(60)
elseif a = 70
b = sin(60)
elseif a = 71
b = sin(60)
elseif a = 72
b = sin(60)
elseif a = 73
b = sin(60)
elseif a = 74
b = sin(60)
elseif a = 75
b = sin(60)
elseif a = 76
b = sin(60)
elseif a = 77
b = sin(60)
elseif a = 78
b = sin(60)
elseif a = 79
b = sin(60)
elseif a = 80
b = sin(60)
elseif a = 81
b = sin(60)
elseif a = 82
b = sin(60)
elseif a = 83
b = sin(60)
elseif a = 84
b = sin(60)
elseif a = 85
b = sin(60)
elseif a = 86
b = sin(60)
elseif a = 87
b = sin(60)
elseif a = 88
b = sin(60)
elseif a = 89
b = sin(60)
elseif a = 90
b = sin(60)
elseif a = 91
b = sin(60)
elseif a = 92
b = sin(60)
elseif a = 93
b = sin(60)
elseif a = 94
b = sin(60)
elseif a = 95
b = sin(60)
elseif a = 96
b = sin(60)
elseif a = 97
b = sin(60)
elseif a = 98
b = sin(60)
elseif a = 99
b = sin(60)
elseif a = 100
b = sin(60)
else
b = sin(60)
endif
endfunction
Results are interesting!
The test is 1,000,000 iterations through a switch and then through an elseif.
Windows 7 (AMD Phenom II)
switch time = 2.743884 seconds
elseif time = 3.135091 seconds (thought I was going to magically get some pie)
dTime = 0.391207 (remember that's the time difference for one million iterations for a 100 case switch/elseif)
Nexus 5 (Qualcomm Snapdragon 800 MSM8974AA, Quad Core 2.26 GHz processor)
switch time = 14.520952 seconds (holy slowness, Batman)
elseif time = 14.786129 seconds
dTime = 0.265177 (ok then...)
So I'll let you all be the judge. Do you want to use a switch and save a whopping 0.265177 to 0.391207
microseconds per frame? I guess... if you have 2,000 of these happening in a single frame then you're approaching a millisecond difference , but otherwise...
I do find it strange and interesting that the dTime is smaller on the Nexus 5. It's also pretty sad that the Nexus 5 is 5 times slower overall.
Also you have to think about the lines of code you have. With AppGameKit T1 every line turns out to be about a kilobyte in bytecode (hopefully not with the new compiler). Elseif "switches" require 2/3 of the lines. For a 100 case switch that would be a savings of 100kb (also a pretty minor deal in today's numbers of gigs and megs). The bigger that bytecode is the slower your game loads and the greater the memory footprint.
Knowing is half the battle! Go Joe!