# Performance

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

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

**Page:** 113

---

## [Help using @btime correctly](https://discourse.julialang.org/t/help-using-btime-correctly/43433)

<div class="topic-metadata">

**Author:** [@jackf](https://discourse.julialang.org/u/jackf)\
**Replies:** 5\
**Last updated:** [July 21, 2020, 3:44pm UTC](https://discourse.julialang.org/t/help-using-btime-correctly/43433 "2020-07-21T15:44:40Z")

</div>

https://github.com/JuliaLang/julia/issues/36751#issuecomment-661883249 I’ve been told I’m not using @btime correctly. Can someone please explain how to profile the allocations of this function without allocating the out…

---

## [Reducing dynamic dispatch using type inference?](https://discourse.julialang.org/t/reducing-dynamic-dispatch-using-type-inference/43233)

<div class="topic-metadata">

**Author:** [@gobs](https://discourse.julialang.org/u/gobs)\
**Replies:** 4\
**Last updated:** [July 20, 2020, 7:17am UTC](https://discourse.julialang.org/t/reducing-dynamic-dispatch-using-type-inference/43233 "2020-07-20T07:17:37Z")

</div>

First of all, apologies for the terrible title, but I’m having a hard time describing what I want to do. I’ve written a lot of my code for an optimisation problem to look something like this: using JuMP # Function def…

---

## [Built-in vs. user-defined functions](https://discourse.julialang.org/t/built-in-vs-user-defined-functions/43213)

<div class="topic-metadata">

**Author:** [@andreas.karatzas](https://discourse.julialang.org/u/andreas.karatzas)\
**Replies:** 13\
**Last updated:** [July 18, 2020, 2:07pm UTC](https://discourse.julialang.org/t/built-in-vs-user-defined-functions/43213 "2020-07-18T14:07:50Z")

</div>

Hello, I am relatively new to Julia. I am mainly interested in Julia because of the performance. There are some functions that are built in Julia like sum(). A custom sum function is worse in performance than the built-…

---

## [Performance issue when searching for an occurrence in larger matrix](https://discourse.julialang.org/t/performance-issue-when-searching-for-an-occurrence-in-larger-matrix/43209)

<div class="topic-metadata">

**Author:** [@a.fas](https://discourse.julialang.org/u/a.fas)\
**Replies:** 3\
**Last updated:** [July 18, 2020, 1:11am UTC](https://discourse.julialang.org/t/performance-issue-when-searching-for-an-occurrence-in-larger-matrix/43209 "2020-07-18T01:11:39Z")

</div>

I wrote some code that searches a large matrix to find occurrences of a given vector. MWE: A = repeat(\[1 2 3; 4 5 6; 7 8 9\], 100, 1); b = \[4; 5; 6\]; In this case, what I would want is a boolean vector that is true for …

---

## [Worse Performance with Approximate Minimum Degree Reordering of Sparse Matrices + LU Than \`\\\`?](https://discourse.julialang.org/t/worse-performance-with-approximate-minimum-degree-reordering-of-sparse-matrices-lu-than/43212)

<div class="topic-metadata">

**Author:** [@jchen975](https://discourse.julialang.org/u/jchen975)\
**Replies:** 4\
**Last updated:** [July 18, 2020, 12:17am UTC](https://discourse.julialang.org/t/worse-performance-with-approximate-minimum-degree-reordering-of-sparse-matrices-lu-than/43212 "2020-07-18T00:17:43Z")

</div>

I’m trying to test the supposed boost in performance (as seen from Matlab) when AMD reordering is used before factorization with the lu when solving Ax = b, where A is a real valued n \\times n sparse matrix. Here is my…

---

## [Reduce vs. foldl: performance and precision](https://discourse.julialang.org/t/reduce-vs-foldl-performance-and-precision/43231)

<div class="topic-metadata">

**Author:** [@Boo](https://discourse.julialang.org/u/Boo)\
**Replies:** 11\
**Last updated:** [July 17, 2020, 9:44pm UTC](https://discourse.julialang.org/t/reduce-vs-foldl-performance-and-precision/43231 "2020-07-17T21:44:35Z")

</div>

Hi guys, Can you explain me, please, the difference in performance and precision between reduce and foldl? julia\> using BenchmarkTools julia\> a = rand(10^7) 10000000-element Array{Float64,1}: 0.8488959437260439 0.76…

---

## [Memory allocations when converting from NamedTuples to DataFrame](https://discourse.julialang.org/t/memory-allocations-when-converting-from-namedtuples-to-dataframe/43171)

<div class="topic-metadata">

**Author:** [@miromarszal](https://discourse.julialang.org/u/miromarszal)\
**Replies:** 4\
**Last updated:** [July 17, 2020, 7:37am UTC](https://discourse.julialang.org/t/memory-allocations-when-converting-from-namedtuples-to-dataframe/43171 "2020-07-17T07:37:44Z")

</div>

I have been struggling with this since a while. When I’m trying to convert an Array of NamedTuple to DataFrame, I’m seeing excessive memory allocations. Consider the following stripped-down example: using DataFrames usi…

---

## [Read array of strings into Dictionary of DataFrames](https://discourse.julialang.org/t/read-array-of-strings-into-dictionary-of-dataframes/43202)

<div class="topic-metadata">

**Author:** [@evad](https://discourse.julialang.org/u/evad)\
**Replies:** 1\
**Last updated:** [July 17, 2020, 6:19am UTC](https://discourse.julialang.org/t/read-array-of-strings-into-dictionary-of-dataframes/43202 "2020-07-17T06:19:19Z")

</div>

Hi, I have an array of strings where each string is a stream of multiple tables. And the final step of my function is to create and return a dictionary: function readTables(str) nStrs = split(str,"\\r\\n%T\\t") fHea…

---

## [Confusion about optimizations in @code\_typed](https://discourse.julialang.org/t/confusion-about-optimizations-in-code-typed/43197)

<div class="topic-metadata">

**Author:** [@xitology](https://discourse.julialang.org/u/xitology)\
**Replies:** 0\
**Last updated:** [July 16, 2020, 8:52pm UTC](https://discourse.julialang.org/t/confusion-about-optimizations-in-code-typed/43197 "2020-07-16T20:52:39Z")

</div>

I’m trying to learn how to optimize Julia code, and at some point I discovered I don’t understand the behavior of @code\_typed. I defined a simple recursive Fibonacci function: julia\> fib(n) = n \<= 1 ? n : fib(n-1) + fi…

---

## [Optimize combination of element-wise products and matrix multiplication](https://discourse.julialang.org/t/optimize-combination-of-element-wise-products-and-matrix-multiplication/43088)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 10\
**Last updated:** [July 15, 2020, 4:38pm UTC](https://discourse.julialang.org/t/optimize-combination-of-element-wise-products-and-matrix-multiplication/43088 "2020-07-15T16:38:31Z")

</div>

Hello everyone, I heavily use the following operation in my code: d = (A .\* B)\*c where A, B \\in R^{n\_x,n\_y}, c \\in R^{n\_y} and d \\in R^{n\_x}. I couldn’t find a faster way to compute this than the vectorized form d = (…

---

## [Multithreading a loop with ARPACK eigs()](https://discourse.julialang.org/t/multithreading-a-loop-with-arpack-eigs/43031)

<div class="topic-metadata">

**Author:** [@dehond](https://discourse.julialang.org/u/dehond)\
**Replies:** 6\
**Last updated:** [July 15, 2020, 9:30am UTC](https://discourse.julialang.org/t/multithreading-a-loop-with-arpack-eigs/43031 "2020-07-15T09:30:10Z")

</div>

I’m attempting to multithread a calculation in which I loop over a function that calls on ARPACK’s eigs(). However, whenever I insert the Threads.@threads macro in front of the loop I either get an error or Julia crashes…

---

## [Help with NearestNeighbours and array reduction](https://discourse.julialang.org/t/help-with-nearestneighbours-and-array-reduction/43094)

<div class="topic-metadata">

**Author:** [@sparrowhawk](https://discourse.julialang.org/u/sparrowhawk)\
**Replies:** 0\
**Last updated:** [July 15, 2020, 1:13am UTC](https://discourse.julialang.org/t/help-with-nearestneighbours-and-array-reduction/43094 "2020-07-15T01:13:30Z")

</div>

Hi, I’m trying to find a list of points within range of given co-ordinates, using NearestNeighbours using NearestNeighbors coords = \[0. 1 0 1\] balltree = BallTree(coords) rsearch = 1.0 points = \[0.5, 0.5\] i…

---

## [Fast sum of two sparse matrices and the Hadamard product of sparse and dense matrices](https://discourse.julialang.org/t/fast-sum-of-two-sparse-matrices-and-the-hadamard-product-of-sparse-and-dense-matrices/43029)

<div class="topic-metadata">

**Author:** [@nhavt](https://discourse.julialang.org/u/nhavt)\
**Replies:** 0\
**Last updated:** [July 14, 2020, 10:02am UTC](https://discourse.julialang.org/t/fast-sum-of-two-sparse-matrices-and-the-hadamard-product-of-sparse-and-dense-matrices/43029 "2020-07-14T10:02:22Z")

</div>

Hello all, I would like to obtain the sum of two sparse matrices (see question 1) and the Hadamard product of a sparse matrix and a dense matrix (see question 2). Below is my current implementation. However, it is quite…

---

## [Interpolation into Threads.@spawn macro fails for certain kinds of Structs](https://discourse.julialang.org/t/interpolation-into-threads-spawn-macro-fails-for-certain-kinds-of-structs/42964)

<div class="topic-metadata">

**Author:** [@pyrex41](https://discourse.julialang.org/u/pyrex41)\
**Replies:** 9\
**Last updated:** [July 13, 2020, 10:18pm UTC](https://discourse.julialang.org/t/interpolation-into-threads-spawn-macro-fails-for-certain-kinds-of-structs/42964 "2020-07-13T22:18:53Z")

</div>

According to the docs for Threads.@spawn, you can interpolate an argument via $ and it will spawn the task with a copy of the variable. I have found that when I use a custom struct that use SparseArrays, that this behavi…

---

## [Calculate (I/A)^(2/3) with no allocations with Unitful](https://discourse.julialang.org/t/calculate-i-a-2-3-with-no-allocations-with-unitful/42998)

<div class="topic-metadata">

**Author:** [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)\
**Replies:** 1\
**Last updated:** [July 13, 2020, 10:17pm UTC](https://discourse.julialang.org/t/calculate-i-a-2-3-with-no-allocations-with-unitful/42998 "2020-07-13T22:17:00Z")

</div>

See below. I’m trying to calculate this quantity without allocation. I know that exponentiation and units is tricky since a rational exponent is stored in the type of each unitful quantity, but even when I try to do all …

---

## [Repeated vector vector multiplication to obtain matrix](https://discourse.julialang.org/t/repeated-vector-vector-multiplication-to-obtain-matrix/42980)

<div class="topic-metadata">

**Author:** [@morkip](https://discourse.julialang.org/u/morkip)\
**Replies:** 4\
**Last updated:** [July 13, 2020, 2:09pm UTC](https://discourse.julialang.org/t/repeated-vector-vector-multiplication-to-obtain-matrix/42980 "2020-07-13T14:09:32Z")

</div>

In my application I am running many iterations of a multiplication like this mat = vec1 .\* vec2'. The current implementation is like this dP\_dw = zeros(Float64, (number\_of\_states, settings.n\_vis \* 2, settings.n\_hid)) f…

---

## [Program Structure when muliple routines need to access State](https://discourse.julialang.org/t/program-structure-when-muliple-routines-need-to-access-state/42918)

<div class="topic-metadata">

**Author:** [@pyrex41](https://discourse.julialang.org/u/pyrex41)\
**Replies:** 2\
**Last updated:** [July 13, 2020, 1:24pm UTC](https://discourse.julialang.org/t/program-structure-when-muliple-routines-need-to-access-state/42918 "2020-07-13T13:24:01Z")

</div>

I have a program where I have an input feed (via ZMQ) that constantly updates an Array to maintain current state. I have other processes (either separate Tasks via @async or maybe on other threads via multithreading, sti…

---

## [Poor performance multiplying many (large) matrices multithreaded](https://discourse.julialang.org/t/poor-performance-multiplying-many-large-matrices-multithreaded/42866)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 11\
**Last updated:** [July 13, 2020, 1:30am UTC](https://discourse.julialang.org/t/poor-performance-multiplying-many-large-matrices-multithreaded/42866 "2020-07-13T01:30:12Z")

</div>

I am trying to multiply a bunch of (large and differently sized) matrices, and then do some reduction following each multiply. Basically I tried to do this in a multithreaded loop, where I see good speed gains for small…

---

## [Multiplication performance](https://discourse.julialang.org/t/multiplication-performance/42862)

<div class="topic-metadata">

**Author:** [@Joao\_Barata](https://discourse.julialang.org/u/Joao_Barata)\
**Replies:** 8\
**Last updated:** [July 10, 2020, 6:42pm UTC](https://discourse.julialang.org/t/multiplication-performance/42862 "2020-07-10T18:42:05Z")

</div>

Hey guys, Here is a very simple code I’m using: function tax\_labor(τ0\_y::Real,τ1\_y::Real,ρ\_τ::Real,barρ::Real,earn::Real,rent::Real) τ0\_y\*(earn - min(ρ\_τ\*rent,barρ))^(1.0-τ1\_y) end If I do @btime, I get 9.6 ns. No…

---

## [Matrix multiplication and element-wise operations without extra pre-allocation of memory](https://discourse.julialang.org/t/matrix-multiplication-and-element-wise-operations-without-extra-pre-allocation-of-memory/42855)

<div class="topic-metadata">

**Author:** [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Replies:** 5\
**Last updated:** [July 10, 2020, 5:45pm UTC](https://discourse.julialang.org/t/matrix-multiplication-and-element-wise-operations-without-extra-pre-allocation-of-memory/42855 "2020-07-10T17:45:35Z")

</div>

Hi, I would like to perform the following element operations to a matrix W (m rows and n columns): W(i, j) := a\*W(i, j) - b\*d(j)y(i), where a and b are scalars, d(j) are the elements of a vector d with n elements, and…

---

## [Solve the System of Equations (J' J + μI) x = J'v](https://discourse.julialang.org/t/solve-the-system-of-equations-j-j-i-x-jv/42766)

<div class="topic-metadata">

**Author:** [@Norman](https://discourse.julialang.org/u/Norman)\
**Replies:** 6\
**Last updated:** [July 10, 2020, 2:36pm UTC](https://discourse.julialang.org/t/solve-the-system-of-equations-j-j-i-x-jv/42766 "2020-07-10T14:36:44Z")

</div>

I have a square sparse matrix J of size n \* n where n can be around 1 million. μ is a scalar. I is the identity matrix. v is a vector. The system to be solved is (J'J + μI) x = J'v What I have now is the following: H…

---

## [Gradient of fields in data structure](https://discourse.julialang.org/t/gradient-of-fields-in-data-structure/42820)

<div class="topic-metadata">

**Author:** [@mopg](https://discourse.julialang.org/u/mopg)\
**Replies:** 2\
**Last updated:** [July 10, 2020, 6:40am UTC](https://discourse.julialang.org/t/gradient-of-fields-in-data-structure/42820 "2020-07-10T06:40:11Z")

</div>

I am trying to do some design optimization using a gradient-based method. For that I have written an analysis code that has a ton of parameters (some of which I want to optimize), that are stored in data structures (stru…

---

## [Setdiff along a dimension](https://discourse.julialang.org/t/setdiff-along-a-dimension/42801)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 2\
**Last updated:** [July 9, 2020, 9:25pm UTC](https://discourse.julialang.org/t/setdiff-along-a-dimension/42801 "2020-07-09T21:25:30Z")

</div>

Hello, I am transferring some code from Matlab. In Matlab, the function setdiff can take as input two 2D-arrays A and B, and returns the rows of A that are not in B. In Julia, setdiff is working on collection of iterab…

---

## [Multigrid solver prototype (GMG) and simple Lid Cavity solver](https://discourse.julialang.org/t/multigrid-solver-prototype-gmg-and-simple-lid-cavity-solver/41969)

<div class="topic-metadata">

**Author:** [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Replies:** 37\
**Last updated:** [July 9, 2020, 1:48pm UTC](https://discourse.julialang.org/t/multigrid-solver-prototype-gmg-and-simple-lid-cavity-solver/41969 "2020-07-09T13:48:21Z")

</div>

The following GitHub - triscale-innov/LidJul.jl: GMG, Poisson solver and Lid cavity repo contains a simple Julia implementation of a Geometric Multi-Grid (GMG) solver. This solver is compared with available Julia linear …

---

## [Calculating all possible combinations](https://discourse.julialang.org/t/calculating-all-possible-combinations/42789)

<div class="topic-metadata">

**Author:** [@Alex\_Z](https://discourse.julialang.org/u/Alex_Z)\
**Replies:** 8\
**Last updated:** [July 9, 2020, 6:52pm UTC](https://discourse.julialang.org/t/calculating-all-possible-combinations/42789 "2020-07-09T18:52:04Z")

</div>

Hello. I’m having trouble finding an efficient way to calculate all possible combinations from a set of vectors. When they are small using kron\[a,b,c\] where a,b and c are vectors yields good results but the problem occ…

---

## [Debugging Julia HTTP Package Performance bottleneck](https://discourse.julialang.org/t/debugging-julia-http-package-performance-bottleneck/42739)

<div class="topic-metadata">

**Author:** [@dilipjain](https://discourse.julialang.org/u/dilipjain)\
**Replies:** 1\
**Last updated:** [July 8, 2020, 5:49pm UTC](https://discourse.julialang.org/t/debugging-julia-http-package-performance-bottleneck/42739 "2020-07-08T17:49:53Z")

</div>

I was doing performance analysis of Julia HTTP server. A simple HelloWorld API gives around 4K Request/second(1 Core, Max CPU Utilization = 50%). Since the CPU utilisation of Julia process is not 100% I suspect there is …

---

## [Mask on a 1D array](https://discourse.julialang.org/t/mask-on-a-1d-array/42740)

<div class="topic-metadata">

**Author:** [@mleprovost](https://discourse.julialang.org/u/mleprovost)\
**Replies:** 2\
**Last updated:** [July 8, 2020, 3:59pm UTC](https://discourse.julialang.org/t/mask-on-a-1d-array/42740 "2020-07-08T15:59:05Z")

</div>

Hello, I would like to create a “mask” of a n-dimensional vector x whose i-th entrance is masked by 0, i.e xmask = \[x1; x2; ...;xi-1; 0; xi+1; ...; xn\] Is it possible to do this with a “view” and avoid to create a wh…

---

## [Multithreaded parallel prefix scan not faster](https://discourse.julialang.org/t/multithreaded-parallel-prefix-scan-not-faster/42591)

<div class="topic-metadata">

**Author:** [@Ellipse0934](https://discourse.julialang.org/u/Ellipse0934)\
**Replies:** 5\
**Last updated:** [July 8, 2020, 1:12pm UTC](https://discourse.julialang.org/t/multithreaded-parallel-prefix-scan-not-faster/42591 "2020-07-08T13:12:45Z")

</div>

I am trying to write the parallel prefix scan as a multithreaded CPU function. Since the number of processors is small relative to the length of the array It wouldn’t be fruitful to use Hillis-Steele or Belloch scan. In…

---

## [Memory allocation in matrix multiplication](https://discourse.julialang.org/t/memory-allocation-in-matrix-multiplication/42707)

<div class="topic-metadata">

**Author:** [@aaraujo71](https://discourse.julialang.org/u/aaraujo71)\
**Replies:** 2\
**Last updated:** [July 8, 2020, 11:39am UTC](https://discourse.julialang.org/t/memory-allocation-in-matrix-multiplication/42707 "2020-07-08T11:39:53Z")

</div>

I am using matrix multiplication inside large loops and I wonder how I can reduce memory allocation. For example, the following (useless) code function run\_cycle!(R, A, B) for i in 1:1000 R = A\*B end end…

---

## [Benchmark in place functions with @btime wasn't set up properly?](https://discourse.julialang.org/t/benchmark-in-place-functions-with-btime-wasnt-set-up-properly/42705)

<div class="topic-metadata">

**Author:** [@jchen975](https://discourse.julialang.org/u/jchen975)\
**Replies:** 2\
**Last updated:** [July 8, 2020, 4:05am UTC](https://discourse.julialang.org/t/benchmark-in-place-functions-with-btime-wasnt-set-up-properly/42705 "2020-07-08T04:05:52Z")

</div>

I wrote an in-place function that performs the multidimensional Newton-Raphson algorithm, and I’m trying to compare the performance with the original implementation in Matlab. Since I wrote it as an in-place function, I…

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

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