# Performance

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

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

**Page:** 139

---

## [Allocation by StaticArrays in anonymous function/macro](https://discourse.julialang.org/t/allocation-by-staticarrays-in-anonymous-function-macro/14774)

<div class="topic-metadata">

**Author:** [@natschil](https://discourse.julialang.org/u/natschil)\
**Replies:** 2\
**Last updated:** [September 10, 2018, 4:50pm UTC](https://discourse.julialang.org/t/allocation-by-staticarrays-in-anonymous-function-macro/14774 "2018-09-10T16:50:54Z")

</div>

The following code produces 1 allocation of 32 bytes if the function is created by a macro (same effect if it were an anonymous function). It has 0 allocations if the function is not created by a macro. Note that the al…

---

## [Problems with Julia 1.0 on Mac os](https://discourse.julialang.org/t/problems-with-julia-1-0-on-mac-os/14687)

<div class="topic-metadata">

**Author:** [@rverdier](https://discourse.julialang.org/u/rverdier)\
**Replies:** 1\
**Last updated:** [September 7, 2018, 11:04pm UTC](https://discourse.julialang.org/t/problems-with-julia-1-0-on-mac-os/14687 "2018-09-07T23:04:28Z")

</div>

In order to learn Julia, I want to convert my course, Programming in Python with Graphics Applications, to Julia. Using OS 10.13.6 on a MacBook Pro, I immediately ran into two problems: 1: All the docs say to use quit(…

---

## [Performance of zeros() vs. Array{T}()?](https://discourse.julialang.org/t/performance-of-zeros-vs-array-t/14596)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 4\
**Last updated:** [September 6, 2018, 2:26am UTC](https://discourse.julialang.org/t/performance-of-zeros-vs-array-t/14596 "2018-09-06T02:26:32Z")

</div>

In the following function, I see 1.56X speedup when using zeros() function for one input instead of using Array{T}(), which seems odd to me. When I use @btime though, I get the same timings. julia\> function vander(v, x,…

---

## [Compiler optimization for variables and functions](https://discourse.julialang.org/t/compiler-optimization-for-variables-and-functions/14580)

<div class="topic-metadata">

**Author:** [@sairus7](https://discourse.julialang.org/u/sairus7)\
**Replies:** 16\
**Last updated:** [September 5, 2018, 9:56pm UTC](https://discourse.julialang.org/t/compiler-optimization-for-variables-and-functions/14580 "2018-09-05T21:56:42Z")

</div>

C++ compilers can opt-out some extra variables and unused parts of the code. It seems that Julia doesn’t have such optimizations, e.g.: function addone(x::Int) local y::Int = 10 local z::Int = 3 y = y % x …

---

## [Are there any 5-argument versions of \`mul!\` or similar in LinearAlgebra now?](https://discourse.julialang.org/t/are-there-any-5-argument-versions-of-mul-or-similar-in-linearalgebra-now/14585)

<div class="topic-metadata">

**Author:** [@dmbates](https://discourse.julialang.org/u/dmbates)\
**Replies:** 1\
**Last updated:** [September 5, 2018, 4:37pm UTC](https://discourse.julialang.org/t/are-there-any-5-argument-versions-of-mul-or-similar-in-linearalgebra-now/14585 "2018-09-05T16:37:01Z")

</div>

The BLAS routines for multiplication and solving linear systems allow for scalar multipliers, usually written alpha and beta, so that the general mutating version of a matrix product is equivalent to C .= α .\* (A \* B) +…

---

## [How to optimise and be faster than Java?](https://discourse.julialang.org/t/how-to-optimise-and-be-faster-than-java/14457)

<div class="topic-metadata">

**Author:** [@Plamen](https://discourse.julialang.org/u/Plamen)\
**Replies:** 24\
**Last updated:** [September 4, 2018, 12:21am UTC](https://discourse.julialang.org/t/how-to-optimise-and-be-faster-than-java/14457 "2018-09-04T00:21:53Z")

</div>

Hello all I am new to Julia and I try to port something from Java to Julia (in the hope that I would get substantial speedup). The application essentially reads some files with parameters and projects some bond prices o…

---

## [User-dependent meta-programming and recompilation](https://discourse.julialang.org/t/user-dependent-meta-programming-and-recompilation/14468)

<div class="topic-metadata">

**Author:** [@forgot\_the\_comma](https://discourse.julialang.org/u/forgot_the_comma)\
**Replies:** 7\
**Last updated:** [September 3, 2018, 4:42pm UTC](https://discourse.julialang.org/t/user-dependent-meta-programming-and-recompilation/14468 "2018-09-03T16:42:52Z")

</div>

So if you can’t tell by my username, I’m a horrendous programmer. That said, I’m hoping to get opinions on the following: 1. What would actually be a decent way to achieve this 2. Is there any hope for user-dependent m…

---

## [How to accelerate matrix operations(multiplication, add, inverse) in a for loop?](https://discourse.julialang.org/t/how-to-accelerate-matrix-operations-multiplication-add-inverse-in-a-for-loop/14157)

<div class="topic-metadata">

**Author:** [@complexfilter](https://discourse.julialang.org/u/complexfilter)\
**Replies:** 22\
**Last updated:** [September 2, 2018, 6:35am UTC](https://discourse.julialang.org/t/how-to-accelerate-matrix-operations-multiplication-add-inverse-in-a-for-loop/14157 "2018-09-02T06:35:49Z")

</div>

How to accelerate typical matrix operations in a for loop? I am currently rewriting my Matlab code to Julia. However, I find it only 3.5X the speed as Matlab. Are there any ways to further improve the Julia speed? Like…

---

## [Memory allocations in for loop variable](https://discourse.julialang.org/t/memory-allocations-in-for-loop-variable/14332)

<div class="topic-metadata">

**Author:** [@amit112amit](https://discourse.julialang.org/u/amit112amit)\
**Replies:** 28\
**Last updated:** [August 31, 2018, 3:39pm UTC](https://discourse.julialang.org/t/memory-allocations-in-for-loop-variable/14332 "2018-08-31T15:39:29Z")

</div>

Can someone explain how to minimize the memory allocations in the line for i=1:N. The following is output from running --track-allocation=user for a simple function. - using LinearAlgebra: norm - functi…

---

## [Function runs much slower from the Julia command prompt](https://discourse.julialang.org/t/function-runs-much-slower-from-the-julia-command-prompt/14305)

<div class="topic-metadata">

**Author:** [@pythonuser](https://discourse.julialang.org/u/pythonuser)\
**Replies:** 5\
**Last updated:** [August 31, 2018, 12:06pm UTC](https://discourse.julialang.org/t/function-runs-much-slower-from-the-julia-command-prompt/14305 "2018-08-31T12:06:50Z")

</div>

Ok, so I am a relatively new Julia user. I have a program which uses parallelism. When i run a test script to execute the function from the Juno editor, the function execution speed is good. However, when i run the same…

---

## [Program execution is really slow from command line/HTTP server endpoint](https://discourse.julialang.org/t/program-execution-is-really-slow-from-command-line-http-server-endpoint/14307)

<div class="topic-metadata">

**Author:** [@pythonuser](https://discourse.julialang.org/u/pythonuser)\
**Replies:** 2\
**Last updated:** [August 31, 2018, 6:27am UTC](https://discourse.julialang.org/t/program-execution-is-really-slow-from-command-line-http-server-endpoint/14307 "2018-08-31T06:27:32Z")

</div>

Ok, so I am a relatively new Julia user. I have a program which uses parallelism. I am also building an API endpoint around this program using HTTP.jl. The function execution time is really fast from the Juno editor. Ho…

---

## [Pmap performance regression: pmap(x-\>f(x,y), X) creates copies of y](https://discourse.julialang.org/t/pmap-performance-regression-pmap-x-f-x-y-x-creates-copies-of-y/14221)

<div class="topic-metadata">

**Author:** [@kaskarn](https://discourse.julialang.org/u/kaskarn)\
**Replies:** 9\
**Last updated:** [August 30, 2018, 3:16am UTC](https://discourse.julialang.org/t/pmap-performance-regression-pmap-x-f-x-y-x-creates-copies-of-y/14221 "2018-08-30T03:16:00Z")

</div>

Updating some code from 0.5 to 1.0 massively slowed pmap calls for our use case. Briefly, distributing the computation of f(x,arg) over the set X seems to copy and send arg during each iteration. This becomes a problem …

---

## [JuMP "getvalue" suddenly very slow](https://discourse.julialang.org/t/jump-getvalue-suddenly-very-slow/14259)

<div class="topic-metadata">

**Author:** [@shoshievass](https://discourse.julialang.org/u/shoshievass)\
**Replies:** 2\
**Last updated:** [August 29, 2018, 8:47pm UTC](https://discourse.julialang.org/t/jump-getvalue-suddenly-very-slow/14259 "2018-08-29T20:47:17Z")

</div>

I’m using JuMP with a fairly large model (the largest component is a dict of @NLexpressions of size 10,254,747). Usually this works fine, and JuMP performs well. Recently, I’ve tried to do a ‘second stage’ optimization …

---

## [How to do chunk matrix/vector multiplication with @threads](https://discourse.julialang.org/t/how-to-do-chunk-matrix-vector-multiplication-with-threads/14173)

<div class="topic-metadata">

**Author:** [@biona001](https://discourse.julialang.org/u/biona001)\
**Replies:** 1\
**Last updated:** [August 28, 2018, 8:56pm UTC](https://discourse.julialang.org/t/how-to-do-chunk-matrix-vector-multiplication-with-threads/14173 "2018-08-28T20:56:46Z")

</div>

I implemented c = Ab using multithreading naively by computing row-wise dot products. I did so on BitArrays because it is the closest thing to the actual data structure in my problem. However, when I tried to switch the…

---

## [Unnecessary materialize in broadcast?](https://discourse.julialang.org/t/unnecessary-materialize-in-broadcast/14141)

<div class="topic-metadata">

**Author:** [@mfalt](https://discourse.julialang.org/u/mfalt)\
**Replies:** 9\
**Last updated:** [August 28, 2018, 8:16pm UTC](https://discourse.julialang.org/t/unnecessary-materialize-in-broadcast/14141 "2018-08-28T20:16:55Z")

</div>

I am wondering if julia will ever automatically fuse broadcast calls. Take the following example: Example: f1(x,y,z) = x .= (x .- y)/z f2(x,y,z) = x .= (x .- y)/.z x = randn(1000); y = randn(1000); z = 2.0 julia\> @cod…

---

## [\`maximum!\` allocates](https://discourse.julialang.org/t/maximum-allocates/14191)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 4\
**Last updated:** [August 28, 2018, 4:13pm UTC](https://discourse.julialang.org/t/maximum-allocates/14191 "2018-08-28T16:13:50Z")

</div>

I get allocations, but I don’t understand why since it is writing the results in a preallocated array. X = rand(10,3,4); x= rand(1,3,4); @btime maximum!($x,$X) # 452.492 ns (6 allocations: 240 bytes)

---

## [Binning Large Collections of Timestamps](https://discourse.julialang.org/t/binning-large-collections-of-timestamps/13581)

<div class="topic-metadata">

**Author:** [@RobertR](https://discourse.julialang.org/u/RobertR)\
**Replies:** 6\
**Last updated:** [August 28, 2018, 3:19pm UTC](https://discourse.julialang.org/t/binning-large-collections-of-timestamps/13581 "2018-08-28T15:19:42Z")

</div>

Hey, I have a large amount of timestamps (in the form of an array of Float64 seconds), and I need to bin them (into ‘counts’, so something like \[1, 10, 40, 122\] binned to 60 seconds would give counts of \[3, 0, 1\] with t…

---

## [Any sorting function in Julia that is as fast as Matlab's maxk?](https://discourse.julialang.org/t/any-sorting-function-in-julia-that-is-as-fast-as-matlabs-maxk/14105)

<div class="topic-metadata">

**Author:** [@complexfilter](https://discourse.julialang.org/u/complexfilter)\
**Replies:** 7\
**Last updated:** [August 28, 2018, 4:35am UTC](https://discourse.julialang.org/t/any-sorting-function-in-julia-that-is-as-fast-as-matlabs-maxk/14105 "2018-08-28T04:35:06Z")

</div>

I found that maxk in Matlab is way faster(4.7 times in Matlab 2018a) than the maxk in Julia. QQ=randn(1000,1); tic; for i=1:10000 \[~,ind\]=maxk(QQ,10); end toc; and tic(); for i=1:10000 ind1=partialsortperm(Q, 1:10, re…

---

## [for loop consumes extreme amount of memory even though operation can be considered "pure"](https://discourse.julialang.org/t/for-loop-consumes-extreme-amount-of-memory-even-though-operation-can-be-considered-pure/14133)

<div class="topic-metadata">

**Author:** [@rongcuid](https://discourse.julialang.org/u/rongcuid)\
**Replies:** 4\
**Last updated:** [August 27, 2018, 3:23pm UTC](https://discourse.julialang.org/t/for-loop-consumes-extreme-amount-of-memory-even-though-operation-can-be-considered-pure/14133 "2018-08-27T15:23:01Z")

</div>

This was originally opened as a github issue #28909, though I was directed here for the question. The behaviour is that, even though the loop itself is pure(except for printing), and that results can be safely discarded…

---

## [How to improve the performance while do matrix operation](https://discourse.julialang.org/t/how-to-improve-the-performance-while-do-matrix-operation/14083)

<div class="topic-metadata">

**Author:** [@Duigi](https://discourse.julialang.org/u/Duigi)\
**Replies:** 13\
**Last updated:** [August 27, 2018, 12:45am UTC](https://discourse.julialang.org/t/how-to-improve-the-performance-while-do-matrix-operation/14083 "2018-08-27T00:45:30Z")

</div>

I am a new Julia user. When doing matrix operations, there is some confusion about the performance of the code. Format 1 C=0 A=\[2 4 1; 4 1 4; 4 2 3\] @time for i=1:10000000 global A=A/i A=A+A' global C=C+sum…

---

## [@distributed and type instability](https://discourse.julialang.org/t/distributed-and-type-instability/14077)

<div class="topic-metadata">

**Author:** [@Igor\_Douven](https://discourse.julialang.org/u/Igor_Douven)\
**Replies:** 0\
**Last updated:** [August 26, 2018, 10:21am UTC](https://discourse.julialang.org/t/distributed-and-type-instability/14077 "2018-08-26T10:21:18Z")

</div>

I have recently updated some code written for Julia 0.6.2 to Julia 1.0.0 and it actually got a bit slower. (Some context: The code is for updating probabilities partly on the basis of incoming information, partly on the …

---

## [Multiple dispatch causes warntype in closure?](https://discourse.julialang.org/t/multiple-dispatch-causes-warntype-in-closure/14029)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 1\
**Last updated:** [August 26, 2018, 12:31am UTC](https://discourse.julialang.org/t/multiple-dispatch-causes-warntype-in-closure/14029 "2018-08-26T00:31:21Z")

</div>

Hello, using 0.7.0. I’m trying to do some refactoring by using multiple-dispatch. In the example below, generator1() has a “better design” compared to generator2(). Unfortunately, generator1() causes some warntype … is…

---

## [Higher-order lazy ranges/iterators](https://discourse.julialang.org/t/higher-order-lazy-ranges-iterators/13995)

<div class="topic-metadata">

**Author:** [@nordlow](https://discourse.julialang.org/u/nordlow)\
**Replies:** 4\
**Last updated:** [August 24, 2018, 11:35pm UTC](https://discourse.julialang.org/t/higher-order-lazy-ranges-iterators/13995 "2018-08-24T23:35:15Z")

</div>

Will Julia (under the hood) in the future fuse the loops of calls such as map(x -\> x + 1, map(x -\> x \* 2, \[1, 2, 3\])) into a single loop, requiring only a single temporary element, regardless of the size of x? Similar …

---

## [Poor performance of multivariate RNG in 1.0](https://discourse.julialang.org/t/poor-performance-of-multivariate-rng-in-1-0/13966)

<div class="topic-metadata">

**Author:** [@kaskarn](https://discourse.julialang.org/u/kaskarn)\
**Replies:** 7\
**Last updated:** [August 24, 2018, 1:23pm UTC](https://discourse.julialang.org/t/poor-performance-of-multivariate-rng-in-1-0/13966 "2018-08-24T13:23:41Z")

</div>

I am updating some code form 0.5.2 to 1.0 and found large drops in performance, largely due to RNG I generated 10M Float64 draws from N(0,1) and MVN(0,I(10)), with both rand() and rand! After running everything a coupl…

---

## [How to speed up my code](https://discourse.julialang.org/t/how-to-speed-up-my-code/13958)

<div class="topic-metadata">

**Author:** [@donquicote](https://discourse.julialang.org/u/donquicote)\
**Replies:** 8\
**Last updated:** [August 24, 2018, 4:33am UTC](https://discourse.julialang.org/t/how-to-speed-up-my-code/13958 "2018-08-24T04:33:57Z")

</div>

Hi there, I am solving a dynamic programming problem (first try in Julia). Previously I solved the same problem in Python. I was expecting Julia solving it much faster than Python, and I don’t get that much improvement.…

---

## [IterTools.jl Partition type stability?](https://discourse.julialang.org/t/itertools-jl-partition-type-stability/13847)

<div class="topic-metadata">

**Author:** [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Replies:** 3\
**Last updated:** [August 22, 2018, 5:39pm UTC](https://discourse.julialang.org/t/itertools-jl-partition-type-stability/13847 "2018-08-22T17:39:28Z")

</div>

Trying some code like: function test\_loop(event\_times) out = 0.0 for (i, event\_time) in partition(event\_times, 2, 1) out += i + event\_time end return out end @code\_warntype test\_loop(\[1.1, 1.8, …

---

## [Anoymous Functions Slow in sort](https://discourse.julialang.org/t/anoymous-functions-slow-in-sort/13891)

<div class="topic-metadata">

**Author:** [@gabrielgellner](https://discourse.julialang.org/u/gabrielgellner)\
**Replies:** 3\
**Last updated:** [August 22, 2018, 5:05pm UTC](https://discourse.julialang.org/t/anoymous-functions-slow-in-sort/13891 "2018-08-22T17:05:07Z")

</div>

Is it expected that an anonymous function is 300x slower than a named function in sort? For example: test = rand(1000) my\_id(x) = x sort(test, by = x -\> x) # 0.074194 sec sort(test, by = identity) # 0.000070 sec sort…

---

## [Fast Interpolations](https://discourse.julialang.org/t/fast-interpolations/13751)

<div class="topic-metadata">

**Author:** [@Juser](https://discourse.julialang.org/u/Juser)\
**Replies:** 15\
**Last updated:** [August 20, 2018, 6:27pm UTC](https://discourse.julialang.org/t/fast-interpolations/13751 "2018-08-20T18:27:39Z")

</div>

I need linear interpolation on a grid to be fast and work with ForwardDiff. The Interpolations.jl package appears to be extremely fast (especially for a large number of interpolations), however it is not compatible with …

---

## ["We find that global names \[sic\] are frequently constants, and declaring them as such greatly improves performance"](https://discourse.julialang.org/t/we-find-that-global-names-sic-are-frequently-constants-and-declaring-them-as-such-greatly-improves-performance/13738)

<div class="topic-metadata">

**Author:** [@chrisjj](https://discourse.julialang.org/u/chrisjj)\
**Replies:** 8\
**Last updated:** [August 20, 2018, 1:28pm UTC](https://discourse.julialang.org/t/we-find-that-global-names-sic-are-frequently-constants-and-declaring-them-as-such-greatly-improves-performance/13738 "2018-08-20T13:28:10Z")

</div>

(From https://docs.julialang.org/en/stable/manual/performance-tips/#man-performance-tips-1 ) Really?? Does the compiler not itself determine that a global variable value is constant, and optimise accordingly?

---

## [Unexpectedly slow performance of "eigs" with a Hermitian view](https://discourse.julialang.org/t/unexpectedly-slow-performance-of-eigs-with-a-hermitian-view/13701)

<div class="topic-metadata">

**Author:** [@danielericparker](https://discourse.julialang.org/u/danielericparker)\
**Replies:** 6\
**Last updated:** [August 20, 2018, 1:28am UTC](https://discourse.julialang.org/t/unexpectedly-slow-performance-of-eigs-with-a-hermitian-view/13701 "2018-08-20T01:28:48Z")

</div>

Solving quantum mechanics problems numerically (via the so-called “exact diagonalization” method) requires finding the lowest several eigenvalue and eigenvector of a large sparse Hermitian matrix. Since one wants to do t…

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

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