# Performance

**URL:** https://discourse.julialang.org/c/usage/perf/37.md?page=38

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 39

---

## [Why is Julia faster than C++ for quicksort?](https://discourse.julialang.org/t/why-is-julia-faster-than-c-for-quicksort/102669)

<div class="topic-metadata">

**Author:** [@mariusd](https://discourse.julialang.org/u/mariusd)\
**Replies:** 15\
**Last updated:** [August 15, 2023, 3:24pm UTC](https://discourse.julialang.org/t/why-is-julia-faster-than-c-for-quicksort/102669 "2023-08-15T15:24:58Z")

</div>

See the following pieces of code for quicksort, adapted from GitHub - JuliaLang/Microbenchmarks: Microbenchmarks comparing the Julia Programming language with other languages. As you can see in the benchmark output, juli…

---

## [DataFrame sort Performance using Query.jl vs SAS PROC SORT](https://discourse.julialang.org/t/dataframe-sort-performance-using-query-jl-vs-sas-proc-sort/41225)

<div class="topic-metadata">

**Author:** [@Dominic\_Pazzula](https://discourse.julialang.org/u/Dominic_Pazzula)\
**Replies:** 19\
**Last updated:** [August 11, 2023, 9:14pm UTC](https://discourse.julialang.org/t/dataframe-sort-performance-using-query-jl-vs-sas-proc-sort/41225 "2023-08-11T21:14:38Z")

</div>

I’m still learning Julia and am converting some SAS code. I have a large DataFrame (3.3M rows, 6 columns) that I am trying to sort. The performance compared to SAS is abysmal. function sort1(simstates) simstates2…

---

## [How to get a zero-overhead view?](https://discourse.julialang.org/t/how-to-get-a-zero-overhead-view/102744)

<div class="topic-metadata">

**Author:** [@Lilith](https://discourse.julialang.org/u/Lilith)\
**Replies:** 16\
**Last updated:** [August 14, 2023, 3:42pm UTC](https://discourse.julialang.org/t/how-to-get-a-zero-overhead-view/102744 "2023-08-14T15:42:40Z")

</div>

In C, I pass around pointers and lengths, constructing views with pointer arithmetic. This is annoying to debug, but quite performant. Is it possible to get equivalent performance with Julia views? I am okay with segfaul…

---

## [Speeding up a function](https://discourse.julialang.org/t/speeding-up-a-function/102703)

<div class="topic-metadata">

**Author:** [@ditfurth](https://discourse.julialang.org/u/ditfurth)\
**Replies:** 43\
**Last updated:** [August 14, 2023, 1:18pm UTC](https://discourse.julialang.org/t/speeding-up-a-function/102703 "2023-08-14T13:18:06Z")

</div>

Hi all, I have a function that needs some speeding up. I tried many things, here is the current state and a minimum working example # using BenchmarkTools, Random, Distributions, Base.Threads Random.seed!(123) market…

---

## [Type-unstable application of \`map\`](https://discourse.julialang.org/t/type-unstable-application-of-map/102771)

<div class="topic-metadata">

**Author:** [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Replies:** 4\
**Last updated:** [August 13, 2023, 8:17pm UTC](https://discourse.julialang.org/t/type-unstable-application-of-map/102771 "2023-08-13T20:17:34Z")

</div>

Consider the following (minimal?) example: julia\> struct A{N} A(::NTuple{N,Int}) where {N} = new{N}() end julia\> t = (1,2) (1, 2) julia\> T = typeof(t) Tuple{Int64, Int64} julia\> using Test julia\> @…

---

## [Generate sub-tuples in an efficient, type-stable way](https://discourse.julialang.org/t/generate-sub-tuples-in-an-efficient-type-stable-way/102750)

<div class="topic-metadata">

**Author:** [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Replies:** 2\
**Last updated:** [August 12, 2023, 5:56pm UTC](https://discourse.julialang.org/t/generate-sub-tuples-in-an-efficient-type-stable-way/102750 "2023-08-12T17:56:14Z")

</div>

Given a NTuple{N, T}, I’d like to generate the collection of all sub-tuples that can be obtained by removing one element from the original tuple. This collection of sub-tuples can be represented as an NTuple{N, NTuple{N-…

---

## [The state of loop optimization in Julia](https://discourse.julialang.org/t/the-state-of-loop-optimization-in-julia/102711)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 1\
**Last updated:** [August 11, 2023, 10:24am UTC](https://discourse.julialang.org/t/the-state-of-loop-optimization-in-julia/102711 "2023-08-11T10:24:49Z")

</div>

We have loop vectorization which optimizes a single, highly restricted loop, then we will have loopmodel with less restriction but no multithreading. Then, there is a “future work” for loopvectorization. Naturally, one w…

---

## [Problem of unnecessarily iterating many times in for loop](https://discourse.julialang.org/t/problem-of-unnecessarily-iterating-many-times-in-for-loop/101319)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 18\
**Last updated:** [August 10, 2023, 7:51pm UTC](https://discourse.julialang.org/t/problem-of-unnecessarily-iterating-many-times-in-for-loop/101319 "2023-08-10T19:51:06Z")

</div>

For the following code it gives output many times(about 40 times) for only three true matches . Unnecessary iteration will decrease performance as far as i know it should give only three output . julia\> using CSV, Data…

---

## [One Julia sys.so is slower than the other](https://discourse.julialang.org/t/one-julia-sys-so-is-slower-than-the-other/102689)

<div class="topic-metadata">

**Author:** [@limonspb](https://discourse.julialang.org/u/limonspb)\
**Replies:** 0\
**Last updated:** [August 10, 2023, 6:14pm UTC](https://discourse.julialang.org/t/one-julia-sys-so-is-slower-than-the-other/102689 "2023-08-10T18:14:34Z")

</div>

Hello dear experts. Might be a weird question. I have two different sys.so files of Julia (precompiled Julia with some third-party packages included, PackageCompiler is used). Both files are Julia 1.6.1. The problem i…

---

## [Julia equivalent of R's quantile function](https://discourse.julialang.org/t/julia-equivalent-of-rs-quantile-function/102584)

<div class="topic-metadata">

**Author:** [@Sandy45](https://discourse.julialang.org/u/Sandy45)\
**Replies:** 7\
**Last updated:** [August 10, 2023, 5:25am UTC](https://discourse.julialang.org/t/julia-equivalent-of-rs-quantile-function/102584 "2023-08-10T05:25:49Z")

</div>

I am trying to convert R code to Julia and need help on below logic conversion. Currently in R they are trying to process each row in percentile\_to df using for loop by passing arguments to function func\_get\_percentile\_…

---

## [Why does indexing with a scalar allocate memory?](https://discourse.julialang.org/t/why-does-indexing-with-a-scalar-allocate-memory/102656)

<div class="topic-metadata">

**Author:** [@qua4tre](https://discourse.julialang.org/u/qua4tre)\
**Replies:** 2\
**Last updated:** [August 9, 2023, 11:44pm UTC](https://discourse.julialang.org/t/why-does-indexing-with-a-scalar-allocate-memory/102656 "2023-08-09T23:44:57Z")

</div>

julia\> @time 2.0; 0.000005 seconds julia\> x = fill(2.0, 3) 3-element Vector{Float64}: 2.0 2.0 2.0 julia\> @time x\[1\]; 0.000009 seconds (1 allocation: 16 bytes) I would have assumed x\[1\] would be a nonallocating …

---

## [ModelingToolkit compilation time for many small simulations](https://discourse.julialang.org/t/modelingtoolkit-compilation-time-for-many-small-simulations/102631)

<div class="topic-metadata">

**Author:** [@Antomek](https://discourse.julialang.org/u/Antomek)\
**Replies:** 5\
**Last updated:** [August 9, 2023, 4:21pm UTC](https://discourse.julialang.org/t/modelingtoolkit-compilation-time-for-many-small-simulations/102631 "2023-08-09T16:21:14Z")

</div>

Hello all, I am in a situation where I want to run many small ODEs, to do an ensemble-type of simulation. I really like using ModelingToolkit, and was trying to use it for this purpose. However, my code is running rea…

---

## [What does @inbounds actually mean?](https://discourse.julialang.org/t/what-does-inbounds-actually-mean/102592)

<div class="topic-metadata">

**Author:** [@johnomotani](https://discourse.julialang.org/u/johnomotani)\
**Replies:** 8\
**Last updated:** [August 8, 2023, 12:40pm UTC](https://discourse.julialang.org/t/what-does-inbounds-actually-mean/102592 "2023-08-08T12:40:16Z")

</div>

In the discussion on https://github.com/JuliaLang/julia/issues/48245 it was mentioned that Just to be clear, the reason we want to remove it is it requires us to compile the code more conservatively, leading to signifi…

---

## [Cache Data Structure for Lazy Array](https://discourse.julialang.org/t/cache-data-structure-for-lazy-array/102388)

<div class="topic-metadata">

**Author:** [@AlexanderNenninger](https://discourse.julialang.org/u/AlexanderNenninger)\
**Replies:** 5\
**Last updated:** [August 8, 2023, 9:28am UTC](https://discourse.julialang.org/t/cache-data-structure-for-lazy-array/102388 "2023-08-08T09:28:00Z")

</div>

I’ve got an implementation of a lazy array (lazyarrays.jl · GitHub), the entries of which are computed on the fly by function calls. From what we can tell it’s already quite fast. Although many algorithms do access the s…

---

## [Optimize for physical cores and caches](https://discourse.julialang.org/t/optimize-for-physical-cores-and-caches/102575)

<div class="topic-metadata">

**Author:** [@taotree](https://discourse.julialang.org/u/taotree)\
**Replies:** 4\
**Last updated:** [August 7, 2023, 8:10pm UTC](https://discourse.julialang.org/t/optimize-for-physical-cores-and-caches/102575 "2023-08-07T20:10:46Z")

</div>

For some analysis where each thread is memory intensive on separate memory, using all logical cores might be suboptimal because then pairs of threads (hyperthreading) on a single core might be thrashing the caches. It se…

---

## [Performance tip for Julia 1.9, docker and Pkg.precompile on older CPUs](https://discourse.julialang.org/t/performance-tip-for-julia-1-9-docker-and-pkg-precompile-on-older-cpus/102561)

<div class="topic-metadata">

**Author:** [@benguela](https://discourse.julialang.org/u/benguela)\
**Replies:** 0\
**Last updated:** [August 7, 2023, 12:50pm UTC](https://discourse.julialang.org/t/performance-tip-for-julia-1-9-docker-and-pkg-precompile-on-older-cpus/102561 "2023-08-07T12:50:28Z")

</div>

We deploy our apps in Docker containers and recently we upgraded to the 1.9 official Julia image. We started experiencing significant slow start up times when running our containers. Note that we run the Pkg.precompile i…

---

## [FFTW.jl support fftw\_plan\_many\_dft?](https://discourse.julialang.org/t/fftw-jl-support-fftw-plan-many-dft/102466)

<div class="topic-metadata">

**Author:** [@diadora77](https://discourse.julialang.org/u/diadora77)\
**Replies:** 6\
**Last updated:** [August 6, 2023, 4:52pm UTC](https://discourse.julialang.org/t/fftw-jl-support-fftw-plan-many-dft/102466 "2023-08-06T16:52:08Z")

</div>

Hi - I have a scenario where I’m working with a large number of 3d arrays and want to efficiently calculate FFT’s for each column. I’ve written a few test functions that iterate in various ways across columns in calcula…

---

## [Symbolics build\_function and usage](https://discourse.julialang.org/t/symbolics-build-function-and-usage/101005)

<div class="topic-metadata">

**Author:** [@Whyborn](https://discourse.julialang.org/u/Whyborn)\
**Replies:** 1\
**Last updated:** [August 5, 2023, 10:59pm UTC](https://discourse.julialang.org/t/symbolics-build-function-and-usage/101005 "2023-08-05T22:59:29Z")

</div>

Hi, I’m having some trouble using the build\_function tool within the Symbolics package, and a question about how build\_function works. The issue I am having is that executing the function generated by build\_function co…

---

## [Why do I get consistently worse performance running as a script than from REPL?](https://discourse.julialang.org/t/why-do-i-get-consistently-worse-performance-running-as-a-script-than-from-repl/102496)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 4\
**Last updated:** [August 5, 2023, 5:15am UTC](https://discourse.julialang.org/t/why-do-i-get-consistently-worse-performance-running-as-a-script-than-from-repl/102496 "2023-08-05T05:15:57Z")

</div>

julia\_ma\_dot\_bench.jl: using LinearAlgebra, BenchmarkTools import MutableArithmetics const MA = MutableArithmetics; setprecision(128); sleep(2) @btime MA.buffered\_operate\_to!(b, o, dot, x, y) setup=(o=BigFloat(); n=50; …

---

## [Looping over struct fieldnames in a type-stable way](https://discourse.julialang.org/t/looping-over-struct-fieldnames-in-a-type-stable-way/102508)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 3\
**Last updated:** [August 5, 2023, 1:10am UTC](https://discourse.julialang.org/t/looping-over-struct-fieldnames-in-a-type-stable-way/102508 "2023-08-05T01:10:52Z")

</div>

I have a function that updates all fields of a struct in a field-specific way. Here an MWE: julia\> mutable struct Foo a b end julia\> calc\_new\_value(x, y) = x\*y calc\_new\_value (generic function wit…

---

## [Can I avoid allocations when broadcasting over slices?](https://discourse.julialang.org/t/can-i-avoid-allocations-when-broadcasting-over-slices/102501)

<div class="topic-metadata">

**Author:** [@jlchan](https://discourse.julialang.org/u/jlchan)\
**Replies:** 3\
**Last updated:** [August 4, 2023, 7:22pm UTC](https://discourse.julialang.org/t/can-i-avoid-allocations-when-broadcasting-over-slices/102501 "2023-08-04T19:22:19Z")

</div>

I was a little surprised to find that broadcasting over slices allocates, even when using view. Here’s a MWE. u = randn(10, 100) ids = reshape(1:100, 10, 10) out = similar(u\[ids\]) function foo1!(out, u, ids) @. out…

---

## [Why is the return type of the following inplace broadcast operation not inferred?](https://discourse.julialang.org/t/why-is-the-return-type-of-the-following-inplace-broadcast-operation-not-inferred/102449)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 5\
**Last updated:** [August 3, 2023, 9:52pm UTC](https://discourse.julialang.org/t/why-is-the-return-type-of-the-following-inplace-broadcast-operation-not-inferred/102449 "2023-08-03T21:52:20Z")

</div>

julia\> @descend\_code\_warntype (Y -\> Y .+= Any\[rand(size(Y))\]\[1\])(rand(2)) (::var"#3#4")(Y) @ Main REPL\[4\]:1 ┌ Warning: couldn't retrieve source of (::var"#3#4")(Y) @ Main REPL\[4\]:1 └ @ TypedSyntax ~/.julia/packages/Typed…

---

## [Best way to take trace of matrix product in Julia?](https://discourse.julialang.org/t/best-way-to-take-trace-of-matrix-product-in-julia/102380)

<div class="topic-metadata">

**Author:** [@hshackle](https://discourse.julialang.org/u/hshackle)\
**Replies:** 17\
**Last updated:** [August 3, 2023, 10:55am UTC](https://discourse.julialang.org/t/best-way-to-take-trace-of-matrix-product-in-julia/102380 "2023-08-03T10:55:33Z")

</div>

My question is essentially a rehash of the Python question posted here. Given two matrices A and B, I would like to compute the trace of A\*B, which does not require evaluating the full matrix multiplication. I’ve include…

---

## [Speeding up matrix exponential and matrix multiplication](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272)

<div class="topic-metadata">

**Author:** [@eveningsilverfox](https://discourse.julialang.org/u/eveningsilverfox)\
**Replies:** 58\
**Last updated:** [August 1, 2023, 4:21pm UTC](https://discourse.julialang.org/t/speeding-up-matrix-exponential-and-matrix-multiplication/102272 "2023-08-01T16:21:04Z")

</div>

I am very new to Julia and trying to convert my python codes to Julia to speed up my work. However, the present Julia version, pasted below, still runs slower than my python version. I see two bottlenecks: (1) the matr…

---

## [Too much garbage collection for a simple vector addition operation](https://discourse.julialang.org/t/too-much-garbage-collection-for-a-simple-vector-addition-operation/102173)

<div class="topic-metadata">

**Author:** [@ducanh-le](https://discourse.julialang.org/u/ducanh-le)\
**Replies:** 12\
**Last updated:** [July 29, 2023, 7:16am UTC](https://discourse.julialang.org/t/too-much-garbage-collection-for-a-simple-vector-addition-operation/102173 "2023-07-29T07:16:02Z")

</div>

Hi everyone, I’m trying to optimize my code. When look at the profiler, the 2nd and the 3rd line below got GC flags: function resourceAvailable(v::Int32, a::Int32, usedResource::Vector{Int32}, md::ModelData) needed…

---

## [X \* y + z does not automatically use FMA instruction](https://discourse.julialang.org/t/x-y-z-does-not-automatically-use-fma-instruction/100640)

<div class="topic-metadata">

**Author:** [@GLOBEX\_CORP](https://discourse.julialang.org/u/GLOBEX_CORP)\
**Replies:** 31\
**Last updated:** [July 27, 2023, 11:14pm UTC](https://discourse.julialang.org/t/x-y-z-does-not-automatically-use-fma-instruction/100640 "2023-07-27T23:14:11Z")

</div>

I am new to Julia and was wondering why the code x \* y + z does not use fmadd where all values are floats, but instead fmul followed by fadd. On the other hand, if I use the @fastmath decorator, the @code\_native changes …

---

## [Help with speeding up this code](https://discourse.julialang.org/t/help-with-speeding-up-this-code/101407)

<div class="topic-metadata">

**Author:** [@Mark\_Szlazak](https://discourse.julialang.org/u/Mark_Szlazak)\
**Replies:** 30\
**Last updated:** [July 10, 2023, 10:45pm UTC](https://discourse.julialang.org/t/help-with-speeding-up-this-code/101407 "2023-07-10T22:45:29Z")

</div>

I am new to this language, tried a few speed up tips and this is the best i got. Is there anything else that can be done to get a significant performance increase? Can you show me how? using Plots, Printf, OffsetArrays …

---

## [Challenge: Can you beat Python and C++ in Int4 Matrix-Vector Multiply Op?](https://discourse.julialang.org/t/challenge-can-you-beat-python-and-c-in-int4-matrix-vector-multiply-op/101588)

<div class="topic-metadata">

**Author:** [@svilupp](https://discourse.julialang.org/u/svilupp)\
**Replies:** 10\
**Last updated:** [July 25, 2023, 9:44pm UTC](https://discourse.julialang.org/t/challenge-can-you-beat-python-and-c-in-int4-matrix-vector-multiply-op/101588 "2023-07-25T21:44:29Z")

</div>

TL;DR How close can we get to 4x speedup if we move from Float16 to Int4 in mat-vec multiply? Hi everyone, It’s challenge time! I’m calling on the Julia community to show Python bitsandbytes (recent release with 2-4x s…

---

## [Squeezing max performance out of findlast](https://discourse.julialang.org/t/squeezing-max-performance-out-of-findlast/102041)

<div class="topic-metadata">

**Author:** [@abulak](https://discourse.julialang.org/u/abulak)\
**Replies:** 0\
**Last updated:** [July 24, 2023, 8:33pm UTC](https://discourse.julialang.org/t/squeezing-max-performance-out-of-findlast/102041 "2023-07-24T20:33:21Z")

</div>

Hey, I have a very simple problem: given a vector v::AbstractVector{\<:Integer} I’d like to find the last index idx such that v\[idx\] ≠ idx. Here’s a demo/test function and some benchmarks. I tried several things but can…

---

## [Solving ODE inside a double for loop](https://discourse.julialang.org/t/solving-ode-inside-a-double-for-loop/101822)

<div class="topic-metadata">

**Author:** [@David\_F](https://discourse.julialang.org/u/David_F)\
**Replies:** 9\
**Last updated:** [July 24, 2023, 1:54pm UTC](https://discourse.julialang.org/t/solving-ode-inside-a-double-for-loop/101822 "2023-07-24T13:54:56Z")

</div>

Hello, I have two for loops, say the outer one iterates on a time variable, and the inner one iterates on a position variable. Inside the position loop, I call ODEproblem() and solve() to get the solution for a system …

[Previous page](https://discourse.julialang.org/c/usage/perf/37.md?page=37)

[Next page](https://discourse.julialang.org/c/usage/perf/37.md?page=39)
