# Dynamic function generation at runtime with Code.eval\_... very slow

**URL:** <https://forum.elixirforum.com/t/dynamic-function-generation-at-runtime-with-code-eval-very-slow/17208>\
**Category:** Questions\
**Tags:** macros, ast, benchmark\
**Created:** [October 10, 2018, 6:24pm UTC](https://forum.elixirforum.com/t/dynamic-function-generation-at-runtime-with-code-eval-very-slow/17208 "2018-10-10T18:24:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![josevalim](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/josevalim/32/1787_2.png) [@josevalim](https://forum.elixirforum.com/u/josevalim)\
**Post date:** [October 11, 2018, 7:49am UTC](https://forum.elixirforum.com/t/dynamic-function-generation-at-runtime-with-code-eval-very-slow/17208/5 "2018-10-11T07:49:14Z")

</div>

> [@hansonkd](#):
>
> However, my question isn’t to debate about the purpose of my program

The purpose of the program definitely matters, because there may be simpler solutions available.

When you are evaluating code at runtime, there are at a minimum 4 or 5 compiler passes involved, to build something that is then evaluated (i.e. invoked by hand and not compiled). In your case, it is not clear why you need to use eval in the first place. Couldn’t you return the function?

```elixir
compiledB = fn vars ->
  %{"my_var" => userVar_0} = vars
  [["(", to_string(userVar_0), ":", to_string(userVar_0), ")"]]
end

```

---

_[View the full topic](https://forum.elixirforum.com/t/dynamic-function-generation-at-runtime-with-code-eval-very-slow/17208)._
