# 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:** 8

<div class="post-metadata">

**Author:** ![hansonkd](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hansonkd/32/12240_2.png) [@hansonkd](https://forum.elixirforum.com/u/hansonkd)\
**Post date:** [October 11, 2018, 2:05pm UTC](https://forum.elixirforum.com/t/dynamic-function-generation-at-runtime-with-code-eval-very-slow/17208/8 "2018-10-11T14:05:34Z")

</div>

Yes, you are probably right that interpreted is probably enough since IO to send the email will most likely be the limiting factor, performance wise.

Just incase anybody reads this in the future, my results on a small template with nested loops.(“compiledFully” uses Code.compile outlined above, “semi-compiled” is traversing the AST and building nested anon functions).

**Compiling once then calling render (compile is outside loop)**

```
Name ips average deviation median 99th %
compiledFully 32.78 M 0.0305 μs ±23.34% 0.0290 μs 0.0580 μs
semi-compiled 0.0337 M 29.71 μs ±33.99% 27 μs 79 μs

Comparison: 
compiledFully 32.78 M
semi-compiled 0.0337 M - 973.78x slower

```

**Compiling every render (compile is inside loop)**

```
Name ips average deviation median 99th %
semi-compiled 9.83 K 0.102 ms ±342.27% 0.0920 ms 0.180 ms
compiledFully 0.105 K 9.50 ms ±3.93% 9.49 ms 10.42 ms

Comparison: 
semi-compiled 9.83 K
compiledFully 0.105 K - 93.37x slower

```

So if you expect to use the compiled template more then 10-50x, it is worth it to compile it to Elixir.

---

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