# Simple For Loops and Speed

**URL:** https://discourse.julialang.org/t/simple-for-loops-and-speed/7158
**Category:** New to Julia
**Tags:** question, performance
**Created:** [November 18, 2017, 8:04pm UTC](https://discourse.julialang.org/t/simple-for-loops-and-speed/7158 "2017-11-18T20:04:01Z")
**Posts on this page:** 1
**Showing post:** 8

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [November 19, 2017, 11:38am UTC](https://discourse.julialang.org/t/simple-for-loops-and-speed/7158/8 "2017-11-19T11:38:08Z")

</div>

> [@ivo\_welch](#):
>
> why was my seemingly simple and straightforward loop so terribly slow?

It’s not that your code is slow, it’s that your _benchmarking_ is slow. When you do the timing in global scope with non-`const` variables, Julia cannot be certain of the types, and cannot compile efficient code.

This is why using `BenchmarkTools` is a good idea. I never do any benchmarking with `@time`, only with `@btime` from `BenchmarkTools`. It takes care of everything for you.

---

_[View the full topic](https://discourse.julialang.org/t/simple-for-loops-and-speed/7158)._
