# Improving runtime

**URL:** <https://discourse.julialang.org/t/improving-runtime/101405>\
**Category:** New to Julia\
**Tags:** matlab, ode\
**Created:** [July 9, 2023, 4:58pm UTC](https://discourse.julialang.org/t/improving-runtime/101405 "2023-07-09T16:58:10Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [July 9, 2023, 5:09pm UTC](https://discourse.julialang.org/t/improving-runtime/101405/2 "2023-07-09T17:09:48Z")

</div>

At first glance, it seems your code performs a lot of unneeded allocations. For Julia to be fast, you want to avoid allocating new memory when you can reuse it instead.  
See the [performance tips](https://docs.julialang.org/en/v1/manual/performance-tips/) for more details, especially the sections about

- [pre-allocating outputs](https://docs.julialang.org/en/v1/manual/performance-tips/#Pre-allocating-outputs)
- [fusing vectorized operations](https://docs.julialang.org/en/v1/manual/performance-tips/#More-dots:-Fuse-vectorized-operations)
- [using views for slices](https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-views)

In many cases it will be as easy as replacing

```julia
for i in 1:n
    x = y - z
end

```

with

```julia
x = # init
for i in 1:n
    x .= y .- z
end

```

whenever you deal with arrays

---

_[View the full topic](https://discourse.julialang.org/t/improving-runtime/101405)._
