Is Julia integral calculation not as fast as MATLAB?

F-YF
Fri, 22 Apr 2022 09:13:55 +0000
Performance

I found it was slow when I used QuadGK.jl to do integral calculation. Then I used MATLAB to make a comparison and found that Julia integral was slower than MATLAB. Here are my comparisons:

julia> using QuadGK

julia> f(x) = (cos(x)^5 - cos(x)^3 + cos(x))*sin(x)^5
f (generic function with 1 method)

julia> @time quadgk(f, -1, 1, rtol=1e-14)
  0.499007 seconds (609.20 k allocations: 34.800 MiB, 1.39% gc time, 99.96% compilation time)
(6.713414395092624e-19, 0.0)

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake)

Results in MATLAB:

f = @(x) ((cos(x).^5 - cos(x).^3 + cos(x)) .* sin(x).^5);

tic
    quadgk(f, -1, 1,'AbsTol',1e-14);
toc

output: 0.145103s

The above tests were performed on the same computer.

Julia integrals are slower on Linux:

julia> using QuadGK

julia> f(x) = (cos(x)^5 - cos(x)^3 + cos(x))*sin(x)^5
f (generic function with 1 method)

julia> @time quadgk(f, -1, 1, rtol=1e-14)
  2.708747 seconds (7.27 M allocations: 175.746 MiB, 1.04% gc time, 20.33% compilation time)
(-5.403687448405256e-18, 5.524260415282572e-29)

julia> versioninfo()
Julia Version 1.7.2
Commit bf53498635 (2022-02-06 15:21 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i9-7980XE CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)

Of course what I’m showing here is just integrating against a particular function, but when I do a lot of integrals Julia is obviously much slower than MATLAB. Is it my improper use of the quadgk function or is this package not perfect? Do you have any good suggestions?

21 posts - 5 participants