3
votes

I am very new to Julia with python background and I am just testing DifferentialEquations package. I run a simple jl script from command line and the problem is that it takes about a minute to run a simple code that Benchmark shows it need a few milliseconds to execute and also it take about 1GB of RAM. Am I doing something wrong or it is quite normal in Julia?

This is the simple script I got from the Tutorial:

import DifferentialEquations
import Plots

pl = Plots
df = DifferentialEquations

f(u,p,t) = 0.98u
u0 = 1.0
tspan = (0.0, 1.0)
prob = df.ODEProblem(f, u0, tspan)
sol = df.solve(prob)

I am using Ubuntu 18.04 and Julia 1.4.

1
Firstly, Plots takes a long time compile, and you don't seem to be using it, so try removing it from the script. Secondly, you should run Julia scripts from the Julia REPL. Running it from the command line will be slow every time, it's just not the right workflow for Julia. - DNF

1 Answers

4
votes

It sounds like what you're seeing is mainly compilation time = Julia compiles native code for any method upon its first invocation, so yes it's normal to see longer runtimes and higher memory usage on the first run. The times reported in benchmarks are usually obtained using the BenchmarkTools package which will run a function multiple times to give a more accurate picture of its actual runtime, discarding the compilation time (similar to Python's %timeit functionality).