$ time julia ./plottest
using Plots took: 11862 milliseconds
plot() took: 3847 milliseconds
Overall: 15709 milliseconds
real 0m15.876s
user 0m15.495s
sys 0m0.392s
$
If I include a “shebang” (either “#!/usr/bin/julia” or “#!/usr/bin/env julia”) in the script and run it, I get the same results: slowness and no plot. I’m only able to produce a plot when running julia interactively. (Not how I anticipated running Julia code long term.)
Q1: Is it normal for “using Plots” to take 10+ seconds when a script runs? Even working interactively, “using Plots” takes ~10s to complete. Plus, 3.8 seconds to plot 2 50-point data sets seems excessive as well. (Maybe cumsum() is the problem in that case?)
Q2: Why is no plot ever produced when plot() is run from a script? I only get the output from plot() when working at the “julia>” prompt.
Yes, it is. A lot of Plots functions get compiled on the first call of the package, and that takes some seconds. If you need to plot interactively keep you Julia section open. The second time you plot something (your second call to plot(…)) will be fast. This is getting better at each release, but still is not ideal.
When running from a script the plot is not shown interactively, because the script ends. You might want to add
savefig("./plot.pdf")
to save plot generated before the end of the script.
You’d need to call display on the plot object in a script to display the plot and then you’d need something to stop the script from terminating, like a readline at the end of the script. Otherwise you will see the plot only for a few microseconds.
You may also want to check out the PackageCompiler package, it allows you to create a so-called sysimage that greatly speeds up the package loading and compilation.
I haven’t gotten far enough into Julia to think about compilation but it is something that attracted me to the language. I’ll give that a look. Thanks…
Julia is still best uses interactively but if you do want to use Julia for scripting I’d consider DaemonMode.jl.
The second time you run the plot script should be fast, just like the second time you plot from the REPL.