# IF...ELSEIF...ELSE performance

**URL:** <https://discourse.julialang.org/t/if-elseif-else-performance/24622>\
**Category:** Performance\
**Created:** [May 26, 2019, 7:12pm UTC](https://discourse.julialang.org/t/if-elseif-else-performance/24622 "2019-05-26T19:12:33Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![c42f](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/c42f/32/52842_2.png) [@c42f](https://discourse.julialang.org/u/c42f)\
**Post date:** [May 27, 2019, 11:38am UTC](https://discourse.julialang.org/t/if-elseif-else-performance/24622/9 "2019-05-27T11:38:18Z")

</div>

> [@drmartinrohde](#):
>
> What would be the best option if, based on the random number, a specific function needs to be called? I guess you cannot make a dictionary of functions …

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.

---

_[View the full topic](https://discourse.julialang.org/t/if-elseif-else-performance/24622)._
