# Perfomance issue when executing a script

**URL:** <https://discourse.julialang.org/t/perfomance-issue-when-executing-a-script/23494>\
**Category:** General Usage\
**Tags:** ttfp\
**Created:** [April 25, 2019, 5:59am UTC](https://discourse.julialang.org/t/perfomance-issue-when-executing-a-script/23494 "2019-04-25T05:59:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phil1](https://avatars.discourse-cdn.com/v4/letter/p/848f3c/32.png) [@phil1](https://discourse.julialang.org/u/phil1)\
**Post date:** [April 25, 2019, 5:59am UTC](https://discourse.julialang.org/t/perfomance-issue-when-executing-a-script/23494/1 "2019-04-25T05:59:48Z")

</div>

I write a simple script, plotex.jl to produce a plot:

```julia
using Plots
pyplot() # Switch to using the PyPlot.jl backend
plot1 = plot(rand(10,10),linewidth=2,title=“Plot 1”)
display(plot1)

```

When I type the code manually into REPL the plot shows immediately after the last line. The plot also shows immediately if I execute the code from REPL with

`julia > include ("plotex.jl")`

When I run the code as a script from a terminal by

$ julia plotex.jl

it takes 27 seconds for the plot to appear! Can anyone explain this?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [April 25, 2019, 11:57am UTC](https://discourse.julialang.org/t/perfomance-issue-when-executing-a-script/23494/2 "2019-04-25T11:57:14Z")

</div>

I am guessing that is you start a fresh REPL and include the file/run the code, it will also take about 27 seconds for the plot to appear.  
The code must compile before it runs, and Plots.jl is notoriously slow to compile. Once it has compiled, it is fast.

If you already ran it once in the REPL, it won’t need to compile again within that session.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [April 25, 2019, 2:39pm UTC](https://discourse.julialang.org/t/perfomance-issue-when-executing-a-script/23494/3 "2019-04-25T14:39:09Z")

</div>

Time-to-first-plot is a well-known issue, see: [Roadmap for a faster time-to-first-plot?](https://discourse.julialang.org/t/roadmap-for-a-faster-time-to-first-plot/22956)

---

<div class="post-metadata">

**Author:** ![doomphoenix-qxz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doomphoenix-qxz/32/7009_2.png) [@doomphoenix-qxz](https://discourse.julialang.org/u/doomphoenix-qxz)\
**Post date:** [April 25, 2019, 6:18pm UTC](https://discourse.julialang.org/t/perfomance-issue-when-executing-a-script/23494/4 "2019-04-25T18:18:05Z")

</div>

Executing scripts in Julia is a little different than Python (for example). I would use the workflow of loading all the packages you need in the REPL first, and then you can repeatedly `include` your source file to run the script over and over. Or even better, you can put everything in your script in a `main()` function, `includet` the script using [Revise.jl](https://github.com/timholy/Revise.jl), and then run your `main()` function over and over again while making and saving changes to the script with a text editor. That’s the workflow I use and scripts always run really fast, after the initial package loading and compilation.
