# Why is this code so slow in julia compared to a numpy implementation?

**URL:** <https://discourse.julialang.org/t/why-is-this-code-so-slow-in-julia-compared-to-a-numpy-implementation/6660>\
**Category:** Performance\
**Tags:** performance\
**Created:** [October 24, 2017, 4:20pm UTC](https://discourse.julialang.org/t/why-is-this-code-so-slow-in-julia-compared-to-a-numpy-implementation/6660 "2017-10-24T16:20:47Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Post date:** [October 24, 2017, 4:40pm UTC](https://discourse.julialang.org/t/why-is-this-code-so-slow-in-julia-compared-to-a-numpy-implementation/6660/6 "2017-10-24T16:40:39Z")

</div>

As the others said, read the performance tip, don’t use global variables, use `BenchmarkTools`. Your first example becomes

```julia
using BenchmarkTools
a=rand(3,3,50);
function test(a)
    for i in (1:size(a,3))
        (5.0.*a[1,:,i]+a[1,:,i]./2.0+4.0)
    end
end
@belapsed test($a) #118 us

```

and use [triple back ticks to set off code section.](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet#code-and-syntax-highlighting)

---

_[View the full topic](https://discourse.julialang.org/t/why-is-this-code-so-slow-in-julia-compared-to-a-numpy-implementation/6660)._
