IF...ELSEIF...ELSE performance

You can certainly make a dictionary of functions and looking an individual function up in the dictionary is probably quite fast. Unfortunately, actually calling that function will be relatively slow because you’d have to go through the generic dispatch machinery.

I think we need some more detail about what these functions will contain, whether they need to be updated dynamically, whether the set of values for g are statically known, etc. Without those, it’s hard to give good advice on how to structure this code.