# How to make my Julia code fast like MATLAB?

**URL:** https://discourse.julialang.org/t/how-to-make-my-julia-code-fast-like-matlab/61678
**Category:** New to Julia
**Tags:** question
**Created:** [May 23, 2021, 12:17pm UTC](https://discourse.julialang.org/t/how-to-make-my-julia-code-fast-like-matlab/61678 "2021-05-23T12:17:02Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)
#### Post date: [May 23, 2021, 1:21pm UTC](https://discourse.julialang.org/t/how-to-make-my-julia-code-fast-like-matlab/61678/3 "2021-05-23T13:21:47Z")

</div>

Since I don’t have your input files, I can obviously not run the code (it would be better to submit a MWE that does not need those files), but I will try to give some suggestions anyway.

Most of the type annotations here do not affect performance at all. The only place where you need the types is in the declaration of the struct fields, and in that case it is crucial for performance that they are _concrete_ types. Some of the fields in your structs are abstractly typed (`Array{Float64}` and `StepRangeLen{Float64}` are not concrete). If you cannot specify them completely, you can use a parametric struct, e.g.:

```julia
struct Gaussian{T<:Circulant, S<:StepRangeLen{Float64}}
    Fx::T
    sigma::Float64
    height::Float64
    fwhm::Float64
    tconv::S
    ntc::Int64
    duration::Float64
    dt::Float64
    tmin::Float64
    tmax::Float64
    nt::Int64
end

```

I didn’t look at the rest of your code yet, this is just the first thing I noticed.

Edit: I didn’t notice at first that you are actually trying to use a special matrix type. In this case, you should of course use `Circulant` instead of `Array` in your struct.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-make-my-julia-code-fast-like-matlab/61678)._
