# Speeding up repeated optimizations within a large loop

**URL:** https://discourse.julialang.org/t/speeding-up-repeated-optimizations-within-a-large-loop/41901
**Category:** Performance
**Tags:** economics, optim, optimization
**Created:** [June 23, 2020, 12:20am UTC](https://discourse.julialang.org/t/speeding-up-repeated-optimizations-within-a-large-loop/41901 "2020-06-23T00:20:50Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)
#### Post date: [June 23, 2020, 4:42am UTC](https://discourse.julialang.org/t/speeding-up-repeated-optimizations-within-a-large-loop/41901/2 "2020-06-23T04:42:08Z")

</div>

Regarding your MWE, it seems like it could be boiled down considerably further. You’re looping over a 6-dimensional grid of conditions, and solving 12 similar optimization problems (per my count) at each grid point. Can you trim that to a single optimization problem at one set of conditions (which should require no more than a few dozen lines of code)? The repeated structure means that any improvements should be easy to generalize.

Is there a particular reason that you chose Optim.jl (which is mostly meant for unconstrained optimization) instead of JuMP? The latter may be able to handle your constraints without resorting to brute force like

```julia
    if c<=0
        utility = -10000.0

```

---

_[View the full topic](https://discourse.julialang.org/t/speeding-up-repeated-optimizations-within-a-large-loop/41901)._
