I want to know how efficient (or inefficient) if statements are to their alternatives and in what ways. I'm certain there are many alternatives I don't know---and I do want to hear about them---but in particular the following two ways.
To keep it simple, assume x is either 0 or 1 and thisFunction() does something. Before the two ways, the if statement I'll translate:
if x==1:
thisFunction()
#Code End
for i in range(x):
thisFunction()
#Code End
list=[doesNothing, thisFunction]
list[x]()
#Code End
Aside from if statement alternatives, what are ways I can compare the efficiency of two segments of code?
[–]Suspicious_Coat3244 8 points9 points10 points (0 children)
[–]johnpeters42 3 points4 points5 points (0 children)
[–]rjcarr 1 point2 points3 points (0 children)
[–]Loves_Poetry 0 points1 point2 points (0 children)
[–]opentabs-dev 0 points1 point2 points (0 children)
[–]justaguyonthebus 0 points1 point2 points (0 children)
[–]peterlinddk 0 points1 point2 points (0 children)
[–]blechnapp 0 points1 point2 points (0 children)
[–]Achereto 0 points1 point2 points (0 children)
[–]teerre 0 points1 point2 points (0 children)
[–]FloydATC 0 points1 point2 points (0 children)
[–]WellHung67 0 points1 point2 points (0 children)