# Meta-programming an if-else statement of user-defined length

**URL:** <https://discourse.julialang.org/t/meta-programming-an-if-else-statement-of-user-defined-length/53525>\
**Category:** Performance\
**Tags:** question, package\
**Created:** [January 18, 2021, 8:47am UTC](https://discourse.julialang.org/t/meta-programming-an-if-else-statement-of-user-defined-length/53525 "2021-01-18T08:47:22Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Skoffer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skoffer/32/378_2.png) [@Skoffer](https://discourse.julialang.org/u/Skoffer)\
**Post date:** [January 18, 2021, 10:06am UTC](https://discourse.julialang.org/t/meta-programming-an-if-else-statement-of-user-defined-length/53525/9 "2021-01-18T10:06:18Z")

</div>

One more thing, maybe it’ll help. It looks like the central (and most heavy computational) function of your package is `RunSR`, which in turn has `niterations` option. If it possible to rewrite your algorithm in a way that `BINOP!` function would be called multiple times for the same `i`, then issue of dynamical dispatch will be complete gone. I mean, if it is possible to do something like

```julia
function RunSR(x, y, niterations, options)
# ... some preliminary calculations
  BINOP!(x, y, niterations, i, options)
# ... some preliminary calculations
end

function BINOP!(x::Array, y, niterations, i, options)
  op = options.binop[i]
  BINOP!(op, x, y, niterations)
end

function BINOP!(op, x, y, niterations)
   for k = 1:niterations
        broadcast!(op, x, x, y)
        # ... do some other calculations
   end
end

```

It’s just an idea, but I hope it is clear - push dynamic dispatch as early in your calculations as possible and proceed to work with well defined types. This way you can avoid meta programming completely.

---

_[View the full topic](https://discourse.julialang.org/t/meta-programming-an-if-else-statement-of-user-defined-length/53525)._
