# Performance & Profiling Tips for Beginner Code

**URL:** <https://discourse.julialang.org/t/performance-profiling-tips-for-beginner-code/100585>\
**Category:** Performance\
**Tags:** performance, profiling\
**Created:** [June 20, 2023, 2:56am UTC](https://discourse.julialang.org/t/performance-profiling-tips-for-beginner-code/100585 "2023-06-20T02:56:38Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![Salmon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/salmon/32/22968_2.png) [@Salmon](https://discourse.julialang.org/u/Salmon)\
**Post date:** [June 21, 2023, 7:53am UTC](https://discourse.julialang.org/t/performance-profiling-tips-for-beginner-code/100585/9 "2023-06-21T07:53:02Z")

</div>

> [@physh](#):
>
> However I am curious, when calling the entire script, why does
> 
> ```julia
> @time X,Y,Z = mat_xyz(var_params, d_arr, abcvals; mu_g=1.0, prefac=-10.0, theta = 0.0);
> @time evals,evecs = eigen(X+Y,Z);
> 
> ```
> 
> yield
> 
> ```julia
> 0.553434 seconds (249.05 k allocations: 30.053 MiB, 2.41% gc time, 71.89% compilation time)
> 0.281798 seconds (20 allocations: 14.695 MiB)
> 
> ```
> 
> even after several executions? Why is it recompiling the function every time?

I think If you include the entire script you effectively re-define the function which needs to be compiled again (although not the functions that are called from other packages, see [this thread](https://discourse.julialang.org/t/does-julia-recompile-if-the-redefinition-of-the-function-is-the-same/90972)). If you want accurate timings, `@btime` is good, in this case it probably is sufficient to simply call the function two times in the script and only time the second call.  
If the compilation time actually matters, you probably should change your workflow by using Revise.jl. For instance, you can have a script that contains the function definitions and another one which runs the calculation and includes the former as `includet("FunctionDefinitions.jl")` (Or, perhaps even better, make a package, which is actually not difficult in julia).  
Revise will make sure that your function definitions stay up to date while only recompiling when it is necessary.

---

_[View the full topic](https://discourse.julialang.org/t/performance-profiling-tips-for-beginner-code/100585)._
