# Julia speed

**URL:** <https://discourse.julialang.org/t/julia-speed/111511>\
**Category:** Performance\
**Tags:** question\
**Created:** [March 12, 2024, 11:19am UTC](https://discourse.julialang.org/t/julia-speed/111511 "2024-03-12T11:19:14Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [March 12, 2024, 11:42pm UTC](https://discourse.julialang.org/t/julia-speed/111511/21 "2024-03-12T23:42:04Z")

</div>

This might be useful, depending on your field: [2021\_FortranCon/benchmark\_vs\_fortran/README.md at main · m3g/2021\_FortranCon · GitHub](https://github.com/m3g/2021_FortranCon/blob/main/benchmark_vs_fortran%2FREADME.md)

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 13, 2024, 12:45am UTC](https://discourse.julialang.org/t/julia-speed/111511/22 "2024-03-13T00:45:39Z")

</div>

> [@Jean\_Michel](#):
>
> `f(n)=iseven(n) ? 1 : -1`  
> is much faster than `(-1)^n`

FastPow.jl will [do this transformation](https://github.com/JuliaMath/FastPow.jl/blob/f76ae9ca817e01a067a53df8c1bf1794e2e35f1c/src/exp_n.jl#L7-L18) for you. However, accumulating terms iteratively, unrolling alternating terms, and similar tricks are usually even better for summing series.

---

<div class="post-metadata">

**Author:** ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Post date:** [March 13, 2024, 12:48am UTC](https://discourse.julialang.org/t/julia-speed/111511/23 "2024-03-13T00:48:15Z")

</div>

If you have not found it yet, this site is a good beginner’s guide to the best ways to write, execute, and share Julia programs:  
[https://modernjuliaworkflows.github.io](https://modernjuliaworkflows.github.io)

---

<div class="post-metadata">

**Author:** ![peDurand](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@peDurand](https://discourse.julialang.org/u/peDurand)\
**Post date:** [March 13, 2024, 8:50am UTC](https://discourse.julialang.org/t/julia-speed/111511/24 "2024-03-13T08:50:26Z")

</div>

That’s great ! Thanks a lot for this link !

---

<div class="post-metadata">

**Author:** ![peDurand](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@peDurand](https://discourse.julialang.org/u/peDurand)\
**Post date:** [March 13, 2024, 8:51am UTC](https://discourse.julialang.org/t/julia-speed/111511/25 "2024-03-13T08:51:26Z")

</div>

Thank you very much for this link ! It will help me a lot ! 🙂

---

<div class="post-metadata">

**Author:** ![TheLateKronos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thelatekronos/32/12824_2.png) [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Post date:** [March 14, 2024, 7:11am UTC](https://discourse.julialang.org/t/julia-speed/111511/26 "2024-03-14T07:11:57Z")

</div>

> [@peDurand](#):
>
> Thanks a lot to all of you who took the time to explain me how to obtain a fast code under Julia. That’s very kind of you ! I learn a lot with your explanations.  
> For the past years, I’ve try several time to work with Julia. But I had problems with installations of some packages, my codes where slow … So, I was doubting of the power of Julia … I think that your help will be decisive in motivating me to seriously learn Julia in order to use it for my courses. !  
> Many many thanks ! 🙂

I just way to say that I see threads of this kind all the time. Especially when it comes to writing fast code, or where the question is asked nicely with all details required to help people answer. There are a lot of really helpful and knowledgable people on this forum, so do not hesitate to ask similar questions! Or do as I do, and creep around other people’s questions to learn more about Julia 😅

P.s. To format you code nicely, enclose it in triple backticks:  
```  
Your code here  
1+1=2  
```  
Which displays as

```julia
Your code here
1+1=2

```

It is one of those things that just make people more likely to help you, because it feels like some effort has been put into writing the question in a way that is easy to read and understand. Some people really put minimal effort into asking questions and doing followup, and they are no fun to help.

Also, it is syntax highlighted as julia code by default on this forum 😁

---

<div class="post-metadata">

**Author:** ![George9000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/george9000/32/23619_2.png) [@George9000](https://discourse.julialang.org/u/George9000)\
**Post date:** [March 14, 2024, 3:20pm UTC](https://discourse.julialang.org/t/julia-speed/111511/27 "2024-03-14T15:20:49Z")

</div>

This [introductory book](https://nostarch.com/practical-julia) written by a physicist may help you and your students in becoming better acquainted with Julia.

---

<div class="post-metadata">

**Author:** ![peDurand](https://avatars.discourse-cdn.com/v4/letter/p/b9e5f3/32.png) [@peDurand](https://discourse.julialang.org/u/peDurand)\
**Post date:** [March 14, 2024, 7:34pm UTC](https://discourse.julialang.org/t/julia-speed/111511/28 "2024-03-14T19:34:10Z")

</div>

Thanks for this advice ! I’ve just bought this book and I’m waiting for it !

---

<div class="post-metadata">

**Author:** ![neophytedave](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/neophytedave/32/202273_2.png) [@neophytedave](https://discourse.julialang.org/u/neophytedave)\
**Post date:** [March 14, 2024, 8:17pm UTC](https://discourse.julialang.org/t/julia-speed/111511/29 "2024-03-14T20:17:00Z")

</div>

“Julia compiles the functions to specialized machine code the first time they are executed. The compilation time here is negligible. If one writes the code outside functions, however, the code is not specialized and runs interpreted, which is slow.”

I just learned something. Thank you for this.

[Previous page](https://discourse.julialang.org/t/julia-speed/111511.md?page=1)
