# Making a Function FASTER!

**URL:** https://discourse.julialang.org/t/making-a-function-faster/50041
**Category:** New to Julia
**Tags:** question
**Created:** [November 12, 2020, 11:04am UTC](https://discourse.julialang.org/t/making-a-function-faster/50041 "2020-11-12T11:04:25Z")
**Posts on this page:** 7
**Page:** 2

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [November 12, 2020, 11:49pm UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/22 "2020-11-12T23:49:45Z")

</div>

Are you saying that after using these macros, all juli code became slow, even code unrelated to the macro and you had to reinstall Julia?

I find it **very** hard to believe that this is what actually happened, but if it did that is a serious bug.

---

<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 13, 2020, 6:07am UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/23 "2020-11-13T06:07:58Z")

</div>

> [@marianoarnaiz](#):
>
> But I don’t know how…

You could start by testing the code I suggested. It may have bugs, but it’s a start. Next, you can try to only compare the parts of the rays surrounding the changed nodes (making sure the assumption is correct, of course).

After that you could move on to more advanced topics, like creating Ray types and so on.

---

<div class="post-metadata">

### Author: ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)
#### Post date: [November 13, 2020, 10:54am UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/24 "2020-11-13T10:54:49Z")

</div>

Hi Mason!.  
Yes. it DID happen like that. I tested other silly codes I have… all slower…  
I am using JuliaPro… maybe is a bug in that version

---

<div class="post-metadata">

### Author: ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)
#### Post date: [November 13, 2020, 11:25am UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/25 "2020-11-13T11:25:38Z")

</div>

Hi DNF.  
I tried your comments and it is working very well!  
Still need to try the “just compared a part of the ray” idea, cause I did it but it was a bit slower.  
I will report back soon!  
Thanks for the help

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [November 13, 2020, 2:15pm UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/26 "2020-11-13T14:15:29Z")

</div>

It would be good if you could put together a reproducible example so others can confirm, as Mason says it would be of serious concern if `@fastmath` (or indeed other macros) would affect completely unrelated code that they’re not being called on.

---

<div class="post-metadata">

### Author: ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)
#### Post date: [November 13, 2020, 8:26pm UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/27 "2020-11-13T20:26:11Z")

</div>

Hi everyone!  
I uploaded a Test1.jl (my main code) and the functions and a small input data to:

[https://github.com/marianoarnaiz/JULIA](https://github.com/marianoarnaiz/JULIA)

If anyone could help me check it a bit. It is very Matlab-ish because is the only thing I have used before.

All tips are welcome.

The algorithm should take an initial point and final point of a ray (united by a linear path) and bend the 8 nodes in the path to get the minimum traveltime across the velocity (I used slowness) model.

---

<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: [November 14, 2020, 10:56am UTC](https://discourse.julialang.org/t/making-a-function-faster/50041/28 "2020-11-14T10:56:49Z")

</div>

As posted above, I think the code can be cleaner if you take advantage of structures to organize data. One ray could be a structure and all rays a vector of those, instead of those multidimensional matrices.

[Previous page](https://discourse.julialang.org/t/making-a-function-faster/50041.md?page=1)
