Which is faster , match VS if elif ?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Manuel

I am quering a variable stored in an autoload singleton, with if elif I must call global.var every time I use the variable. but if I use the match I only call the variable once … will that make the query slightly faster?

Is retrieving global variables that slow?

gmaps | 2019-09-24 12:55

apparently there is no effect on speed

Manuel | 2019-09-24 13:52

:bust_in_silhouette: Reply From: Zylann

match and if get compiled as the same sets of instructions, none is particularly faster than the other. match is essentially a different way to express things in a more concise way. It certainly makes you write the variable only once, but it still has to compare its value for each case (i.e it’s not a jump table like in C).

oh ok, thanks ! very useful

Manuel | 2019-09-24 13:07