# Slow and Memory intensive For Loop

**URL:** https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304
**Category:** Performance
**Tags:** question
**Created:** [March 29, 2024, 5:13pm UTC](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304 "2024-03-29T17:13:51Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [March 29, 2024, 5:34pm UTC](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304/2 "2024-03-29T17:34:06Z")

</div>

Welcome to the forum!

Some remarks:

1. please, enclose any code you share in triple back-ticks like ```
2. if you call a function the first time it gets compiled, so call it a second time to determine the execution time
3. avoid global variables if you need fast execution time

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

Finally, in this line:

```julia
allScans[:, :, ii] = readdlm(joinpath(file_location, file))

```

try to replace `=` with `.=` to avoid allocations.

---

_[View the full topic](https://discourse.julialang.org/t/slow-and-memory-intensive-for-loop/112304)._
