# Matrix storage in julia

**URL:** <https://discourse.julialang.org/t/matrix-storage-in-julia/21015>\
**Category:** General Usage\
**Created:** [February 20, 2019, 4:36pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015 "2019-02-20T16:36:50Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Suraj\_Pawar](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Suraj\_Pawar](https://discourse.julialang.org/u/Suraj_Pawar)\
**Post date:** [February 20, 2019, 4:36pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/1 "2019-02-20T16:36:50Z")

</div>

How is the matrix stored in Julia? Is it row-major storage like in C++ or column-major storage like Fortran? Recently, I converted my Fortran code in Julia. In Fortran, it takes around 1.6 seconds to run the program. In Julia, it took me 12 seconds for the same program. I am using @time to measure the CPU time where the main calculation is done. Is it normal or I can improve the performance of Julia code.  
Thank you.

---

<div class="post-metadata">

**Author:** ![carstenbauer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carstenbauer/32/4981_2.png) [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Post date:** [February 20, 2019, 4:44pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/2 "2019-02-20T16:44:47Z")

</div>

Column-major like Fortran.

This speed difference is certainly not expected. Without seeing the code it’s hard to tell how to improve it though.

Did you look at the [Performance tips](https://docs.julialang.org/en/latest/manual/performance-tips/)?

---

<div class="post-metadata">

**Author:** ![Suraj\_Pawar](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Suraj\_Pawar](https://discourse.julialang.org/u/Suraj_Pawar)\
**Post date:** [February 20, 2019, 4:54pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/3 "2019-02-20T16:54:42Z")

</div>

I was not passing variables to the functions. So, I was accessing global variables in the function where the main calculation is done. After passing the variables as an argument to the function, the execution time reduced to 3.13 seconds. I will look more into performance tips to see if the performance can be further improved.  
Thank you.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [February 20, 2019, 9:09pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/4 "2019-02-20T21:09:16Z")

</div>

Also have a look at

> **[GitHub - JunoLab/Traceur.jl](https://github.com/JunoLab/Traceur.jl)**
>
> Contribute to JunoLab/Traceur.jl development by creating an account on GitHub.

to automatically check if you are following the performance tips

---

<div class="post-metadata">

**Author:** ![ennvvy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ennvvy/32/7816_2.png) [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Post date:** [February 21, 2019, 11:08am UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/5 "2019-02-21T11:08:44Z")

</div>

I have tried using Traceur.jl, to evaluate my code. However, it hangs. (I use Julia 1.1.0, on notebook)

---

<div class="post-metadata">

**Author:** ![Suraj\_Pawar](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Suraj\_Pawar](https://discourse.julialang.org/u/Suraj_Pawar)\
**Post date:** [March 6, 2019, 11:49pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/6 "2019-03-06T23:49:06Z")

</div>

How to use Traceur.jl yo analyze the code? Are there any instruction on how to use the package?  
Thank you.

---

<div class="post-metadata">

**Author:** ![Suraj\_Pawar](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Suraj\_Pawar](https://discourse.julialang.org/u/Suraj_Pawar)\
**Post date:** [March 6, 2019, 11:49pm UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/7 "2019-03-06T23:49:43Z")

</div>

How can I store the CPU time in a variable? @time just prints the execution time by CPU. Thank you.

---

<div class="post-metadata">

**Author:** ![bennedich](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bennedich/32/4894_2.png) [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Post date:** [March 7, 2019, 12:05am UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/8 "2019-03-07T00:05:07Z")

</div>

Use [`@timed`](https://docs.julialang.org/en/latest/base/base/#Base.@timed).

Also check out [BenchmarkTools.jl](https://github.com/JuliaCI/BenchmarkTools.jl) for more accurate benchmarking.

---

<div class="post-metadata">

**Author:** ![Suraj\_Pawar](https://avatars.discourse-cdn.com/v4/letter/s/aca169/32.png) [@Suraj\_Pawar](https://discourse.julialang.org/u/Suraj_Pawar)\
**Post date:** [March 7, 2019, 12:49am UTC](https://discourse.julialang.org/t/matrix-storage-in-julia/21015/9 "2019-03-07T00:49:02Z")

</div>

How can I use profiling or BenchmarkTools to analyze the code?
