# Performance

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

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

**Page:** 137

---

## [V0.6 vs v1.0: keyword memory allocation example](https://discourse.julialang.org/t/v0-6-vs-v1-0-keyword-memory-allocation-example/17061)

<div class="topic-metadata">

**Author:** [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Replies:** 3\
**Last updated:** [November 2, 2018, 12:51am UTC](https://discourse.julialang.org/t/v0-6-vs-v1-0-keyword-memory-allocation-example/17061 "2018-11-02T00:51:17Z")

</div>

The docs suggest preallocating arrays for performance in the following way: function xinc!(ret::AbstractVector{T}, x::T) where T ret\[1\] = x ret\[2\] = x+1 ret\[3\] = x+2 nothing end function loopinc\_preallo…

---

## [Splatting arguments causes ~30x slow down](https://discourse.julialang.org/t/splatting-arguments-causes-30x-slow-down/16964)

<div class="topic-metadata">

**Author:** [@cnliao](https://discourse.julialang.org/u/cnliao)\
**Replies:** 10\
**Last updated:** [November 1, 2018, 3:56pm UTC](https://discourse.julialang.org/t/splatting-arguments-causes-30x-slow-down/16964 "2018-11-01T15:56:49Z")

</div>

I found the performance characteristic not intuitive when trying to splatting arguments into function calls. On Julia v1.0.1 Ubuntu 16.04 I get the following benchmark and numbers: using BenchmarkTools function k1(x1, …

---

## [Comparing Python, Julia, and C++](https://discourse.julialang.org/t/comparing-python-julia-and-c/17019)

<div class="topic-metadata">

**Author:** [@Maurizio\_Tomasi](https://discourse.julialang.org/u/Maurizio_Tomasi)\
**Replies:** 21\
**Last updated:** [November 1, 2018, 1:07pm UTC](https://discourse.julialang.org/t/comparing-python-julia-and-c/17019 "2018-11-01T13:07:53Z")

</div>

I am going to present Julia at the next ADASS (http://adass2018.astro.umd.edu/), and I would like to show its ability to fuse broadcasted operations like .+ and .\*. I have found some weird results, so I would like to as…

---

## [Question about internal representation of Union{Missing, Float64}](https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000)

<div class="topic-metadata">

**Author:** [@Maurizio\_Tomasi](https://discourse.julialang.org/u/Maurizio_Tomasi)\
**Replies:** 2\
**Last updated:** [October 31, 2018, 3:46pm UTC](https://discourse.julialang.org/t/question-about-internal-representation-of-union-missing-float64/17000 "2018-10-31T15:46:17Z")

</div>

I am trying to understand the internals of the datatype Union{Missing, Float64}. From what I understand, this type encodes the presence of elements in the array by means of a hidden Array{UInt8}, which flags which elemen…

---

## [Which sorting algorithm should I use?](https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999)

<div class="topic-metadata">

**Author:** [@Sam](https://discourse.julialang.org/u/Sam)\
**Replies:** 2\
**Last updated:** [October 31, 2018, 12:19pm UTC](https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999 "2018-10-31T12:19:09Z")

</div>

I am currently writing an algorithm where I have to use sortperm multiple times. After reading about this issue https://github.com/JuliaLang/julia/issues/939#issuecomment-288758163 I realized that there seem to be some p…

---

## [Better ways of passing functions around?](https://discourse.julialang.org/t/better-ways-of-passing-functions-around/16971)

<div class="topic-metadata">

**Author:** [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Replies:** 17\
**Last updated:** [October 31, 2018, 11:23am UTC](https://discourse.julialang.org/t/better-ways-of-passing-functions-around/16971 "2018-10-31T11:23:31Z")

</div>

When I pass function around, it causes a huge memory allocation. Like the following: - function f1(x::Float64) 16000000 x = x+3. - end - - mutable struct MyType - x::Float64…

---

## [Performance problem of count?](https://discourse.julialang.org/t/performance-problem-of-count/16873)

<div class="topic-metadata">

**Author:** [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Replies:** 21\
**Last updated:** [October 28, 2018, 7:05pm UTC](https://discourse.julialang.org/t/performance-problem-of-count/16873 "2018-10-28T19:05:10Z")

</div>

Writing code to count the number of inversions of a permutation, I was surprised that it allocates. Thus I wrote what I thought equivalent code with a for loop, and it does not allocate. Here is the code; why is count so…

---

## [Unexpectedly high memory allocation when running n-body simulation](https://discourse.julialang.org/t/unexpectedly-high-memory-allocation-when-running-n-body-simulation/16876)

<div class="topic-metadata">

**Author:** [@novoselrok](https://discourse.julialang.org/u/novoselrok)\
**Replies:** 3\
**Last updated:** [October 28, 2018, 7:19am UTC](https://discourse.julialang.org/t/unexpectedly-high-memory-allocation-when-running-n-body-simulation/16876 "2018-10-28T07:19:25Z")

</div>

I wrote the n-body simulation in Julia, but I’m experiencing unexpectedly high memory allocation (according to the @time macro) when running the simulation for 10.000 bodies (the input file I’m using test1e4.julia.txt · …

---

## [Performance of Memory Mapped Arrays (vs. JLD2)](https://discourse.julialang.org/t/performance-of-memory-mapped-arrays-vs-jld2/16810)

<div class="topic-metadata">

**Author:** [@colddaysend](https://discourse.julialang.org/u/colddaysend)\
**Replies:** 2\
**Last updated:** [October 26, 2018, 9:21am UTC](https://discourse.julialang.org/t/performance-of-memory-mapped-arrays-vs-jld2/16810 "2018-10-26T09:21:04Z")

</div>

I need to generate a very large matrix (too big for memory), so I’m using memory mapped arrays. I’m trying to benchmark the code and understand some of the variation in run times. Right now, I’m looking at the time it t…

---

## [How to efficiently transform vector of structures?](https://discourse.julialang.org/t/how-to-efficiently-transform-vector-of-structures/16816)

<div class="topic-metadata">

**Author:** [@Martin\_Florek](https://discourse.julialang.org/u/Martin_Florek)\
**Replies:** 5\
**Last updated:** [October 26, 2018, 10:30am UTC](https://discourse.julialang.org/t/how-to-efficiently-transform-vector-of-structures/16816 "2018-10-26T10:30:20Z")

</div>

How to efficiently transform vector of structures without unnecessary allocation? We have two structures: struct ApiData name::String reload::Vector{ApiReload} values::Vector{Float64} end struct ApiReload statu…

---

## [Live Plotting Best Practices?](https://discourse.julialang.org/t/live-plotting-best-practices/16571)

<div class="topic-metadata">

**Author:** [@standarddeviant](https://discourse.julialang.org/u/standarddeviant)\
**Replies:** 5\
**Last updated:** [October 25, 2018, 1:16pm UTC](https://discourse.julialang.org/t/live-plotting-best-practices/16571 "2018-10-25T13:16:51Z")

</div>

I have a project where I’m receiving time domain data in packets, that I’d like to plot live. After looking at some options, I decided to go with plain GR.jl. My simulation of MVP code is at the end of my post. To run…

---

## [Explicit Inversion of a random matrix performs the same as Symmetric & SPD](https://discourse.julialang.org/t/explicit-inversion-of-a-random-matrix-performs-the-same-as-symmetric-spd/16732)

<div class="topic-metadata">

**Author:** [@cpsarras](https://discourse.julialang.org/u/cpsarras)\
**Replies:** 6\
**Last updated:** [October 25, 2018, 1:43am UTC](https://discourse.julialang.org/t/explicit-inversion-of-a-random-matrix-performs-the-same-as-symmetric-spd/16732 "2018-10-25T01:43:18Z")

</div>

Hi all, so I was testing how Julia (1.1.0-DEV.452) handles Matrices with different kinds of properties (Symmetric, SPD, UpperTriangular etc.) and how much faster certain operations (i.e. inv(A)) perform based on those p…

---

## [Fastest way to multiply a constant sparse matrix to a vector](https://discourse.julialang.org/t/fastest-way-to-multiply-a-constant-sparse-matrix-to-a-vector/16458)

<div class="topic-metadata">

**Author:** [@briochemc](https://discourse.julialang.org/u/briochemc)\
**Replies:** 7\
**Last updated:** [October 22, 2018, 2:44pm UTC](https://discourse.julialang.org/t/fastest-way-to-multiply-a-constant-sparse-matrix-to-a-vector/16458 "2018-10-22T14:44:41Z")

</div>

One answer to this question about multiplying a constant sparse matrix to a static vector made me wonder: Is there a more performant way of multiplying a constant sparse matrix A to a non-static vector x than doing A \* …

---

## [Dear MIT,Please give us your plan for multithreading?](https://discourse.julialang.org/t/dear-mit-please-give-us-your-plan-for-multithreading/16433)

<div class="topic-metadata">

**Author:** [@564064202](https://discourse.julialang.org/u/564064202)\
**Replies:** 1\
**Last updated:** [October 17, 2018, 12:39pm UTC](https://discourse.julialang.org/t/dear-mit-please-give-us-your-plan-for-multithreading/16433 "2018-10-17T12:39:18Z")

</div>

Dear MIT,Please give us your plan for multithreading?

---

## [When I run my proramm with large arrays, when it ends the momory remain allocated](https://discourse.julialang.org/t/when-i-run-my-proramm-with-large-arrays-when-it-ends-the-momory-remain-allocated/16393)

<div class="topic-metadata">

**Author:** [@dsHitman](https://discourse.julialang.org/u/dsHitman)\
**Replies:** 4\
**Last updated:** [October 17, 2018, 10:51am UTC](https://discourse.julialang.org/t/when-i-run-my-proramm-with-large-arrays-when-it-ends-the-momory-remain-allocated/16393 "2018-10-17T10:51:08Z")

</div>

Hi, how I can dealocate memory after I run my programm? Because when I run my ptogramm with big arrays when it ends the memory remain allocated. I try to use the gc() function but Hulia says “ERROR: LoadError: UndefVarEr…

---

## [Fastest way of doing (constant sparse) \* SVector multiplication](https://discourse.julialang.org/t/fastest-way-of-doing-constant-sparse-svector-multiplication/16365)

<div class="topic-metadata">

**Author:** [@natschil](https://discourse.julialang.org/u/natschil)\
**Replies:** 9\
**Last updated:** [October 16, 2018, 10:40am UTC](https://discourse.julialang.org/t/fastest-way-of-doing-constant-sparse-svector-multiplication/16365 "2018-10-16T10:40:03Z")

</div>

Background: I have an implementation of tricubic interpolation that works, but is ~20x slower than my implementation of trilinear interpolation despite only requiring (in theory) 8x as many memory accesses. Essentially …

---

## [Minimizing Work in Copying/Manipulating Custom Data Structures](https://discourse.julialang.org/t/minimizing-work-in-copying-manipulating-custom-data-structures/16284)

<div class="topic-metadata">

**Author:** [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Replies:** 12\
**Last updated:** [October 16, 2018, 12:45am UTC](https://discourse.julialang.org/t/minimizing-work-in-copying-manipulating-custom-data-structures/16284 "2018-10-16T00:45:21Z")

</div>

I have a computation I want to do where I am using my own data structure (composed of two or more arrays, which, themselves, may be specialized data structures). I want to perform an operation on this data structure in …

---

## [Weird allocation from SharedArrays/StaticArrays](https://discourse.julialang.org/t/weird-allocation-from-sharedarrays-staticarrays/16354)

<div class="topic-metadata">

**Author:** [@natschil](https://discourse.julialang.org/u/natschil)\
**Replies:** 2\
**Last updated:** [October 15, 2018, 6:44pm UTC](https://discourse.julialang.org/t/weird-allocation-from-sharedarrays-staticarrays/16354 "2018-10-15T18:44:49Z")

</div>

Hi, I’m getting an allocation from the following code, which results in a factor 20x slowdown in this MWE: using SharedArrays,BenchmarkTools,StaticArrays U = SharedArray{Float64}(zeros(100,100,100)) function mytestfu…

---

## [Performance input on my code](https://discourse.julialang.org/t/performance-input-on-my-code/16321)

<div class="topic-metadata">

**Author:** [@jarrison](https://discourse.julialang.org/u/jarrison)\
**Replies:** 8\
**Last updated:** [October 15, 2018, 5:00pm UTC](https://discourse.julialang.org/t/performance-input-on-my-code/16321 "2018-10-15T17:00:49Z")

</div>

Hey all! I have just picked up Julia as a fun language to learn and have been translating old python code both as a learning experience and to see just how much performance i can squeeze out of it. I think I have gotten …

---

## [The 2048 challenge: fastest ways to simulate games of 2048 in Julia](https://discourse.julialang.org/t/the-2048-challenge-fastest-ways-to-simulate-games-of-2048-in-julia/16331)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 8\
**Last updated:** [October 15, 2018, 4:44pm UTC](https://discourse.julialang.org/t/the-2048-challenge-fastest-ways-to-simulate-games-of-2048-in-julia/16331 "2018-10-15T16:44:56Z")

</div>

I am sure many of you have played the game 2048. I have been writing a simulation engine for 2048 in Julia which I hope to eventually contribute back to a package like Reinforce.jl as an environment. If you enjoy program…

---

## [Understanding performance using \`@btime\` and \`@code\_warntype\`, \`@code\_llvm\`, etc](https://discourse.julialang.org/t/understanding-performance-using-btime-and-code-warntype-code-llvm-etc/16293)

<div class="topic-metadata">

**Author:** [@dave.f.kleinschmidt](https://discourse.julialang.org/u/dave.f.kleinschmidt)\
**Replies:** 13\
**Last updated:** [October 14, 2018, 8:28pm UTC](https://discourse.julialang.org/t/understanding-performance-using-btime-and-code-warntype-code-llvm-etc/16293 "2018-10-14T20:28:36Z")

</div>

I’m struggling to get my head around some benchmarking and @code\_llvm inspecting that I’ve been doing. The background is I was curious what kind of overhead you get from creating an intermediate Normal distribution in a…

---

## [Is boolean indexing 100 times slower in 1.0?](https://discourse.julialang.org/t/is-boolean-indexing-100-times-slower-in-1-0/16286)

<div class="topic-metadata">

**Author:** [@misha\_mikhasenko](https://discourse.julialang.org/u/misha_mikhasenko)\
**Replies:** 10\
**Last updated:** [October 14, 2018, 11:42am UTC](https://discourse.julialang.org/t/is-boolean-indexing-100-times-slower-in-1-0/16286 "2018-10-14T11:42:38Z")

</div>

d = rand(100) mask = \[fill(false,20)...,fill(true,80)...\]; @time for i in 1:100000 d\[mask\] end Julia-1.0 and 0.7 3.038767 seconds (41.20 M allocations: 1.197 GiB, 4.90% gc time) Julia-0.6.4 0.029932 seconds…

---

## [Inv(transpose(mat) ) causes warntype](https://discourse.julialang.org/t/inv-transpose-mat-causes-warntype/16216)

<div class="topic-metadata">

**Author:** [@tomtom](https://discourse.julialang.org/u/tomtom)\
**Replies:** 1\
**Last updated:** [October 12, 2018, 2:06pm UTC](https://discourse.julialang.org/t/inv-transpose-mat-causes-warntype/16216 "2018-10-12T14:06:54Z")

</div>

hello, I found the following problem in both 1.0.0 and 1.0.1 mat = reshape(collect(1.0:4.0), 2, 2) julia\> @code\_warntype inv(transpose(mat) ) # gives warntype Body::Any @code\_warntype inv(copy(transpose(mat) ) ) …

---

## [Julia / C mutable struct compiles much faster than struct](https://discourse.julialang.org/t/julia-c-mutable-struct-compiles-much-faster-than-struct/16141)

<div class="topic-metadata">

**Author:** [@klowrey](https://discourse.julialang.org/u/klowrey)\
**Replies:** 5\
**Last updated:** [October 12, 2018, 12:25am UTC](https://discourse.julialang.org/t/julia-c-mutable-struct-compiles-much-faster-than-struct/16141 "2018-10-12T00:25:10Z")

</div>

I’ve wrapped a C library for use in Julia, and have encountered a performance benefit to using a mutable struct as opposed to a struct; this is not what I would have expected. In short: the C-library usually deals with p…

---

## [Trig functions very slow](https://discourse.julialang.org/t/trig-functions-very-slow/15335)

<div class="topic-metadata">

**Author:** [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Replies:** 67\
**Last updated:** [October 10, 2018, 9:11am UTC](https://discourse.julialang.org/t/trig-functions-very-slow/15335 "2018-10-10T09:11:25Z")

</div>

I found that some simple mathematical functions, at least trigonometric, are much slower in Julia than e.g. in Python (with numba). Here is a minimalistic example: function f() r = 0. for i in 0:100\_000\_000 - 1 …

---

## [sort(A, dims=1) mixing rows](https://discourse.julialang.org/t/sort-a-dims-1-mixing-rows/16086)

<div class="topic-metadata">

**Author:** [@programista](https://discourse.julialang.org/u/programista)\
**Replies:** 11\
**Last updated:** [October 9, 2018, 7:23pm UTC](https://discourse.julialang.org/t/sort-a-dims-1-mixing-rows/16086 "2018-10-09T19:23:57Z")

</div>

julia\> slow 4811392×2 Array{Any,2}: "Ag" "Aga" ... "zzg" "z" when sort(slow,dims=1) rows are mixed :confused: very denger ! Intuitively sort refers to the table and not each column separately. Is somthi…

---

## [Allocations in function timing](https://discourse.julialang.org/t/allocations-in-function-timing/16081)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 2\
**Last updated:** [October 9, 2018, 4:43pm UTC](https://discourse.julialang.org/t/allocations-in-function-timing/16081 "2018-10-09T16:43:49Z")

</div>

Sorry for hijacking the topic, but as I was playing with the algorithms, I noticed that given this function: julia\> function main(n) r = 0 for i = 1:n i -= 1 r += 1 end …

---

## [Performance increased after adding a if?](https://discourse.julialang.org/t/performance-increased-after-adding-a-if/15359)

<div class="topic-metadata">

**Author:** [@Zhiye\_Xia](https://discourse.julialang.org/u/Zhiye_Xia)\
**Replies:** 4\
**Last updated:** [October 8, 2018, 8:17pm UTC](https://discourse.julialang.org/t/performance-increased-after-adding-a-if/15359 "2018-10-08T20:17:33Z")

</div>

Hi everyone, I was playing with a simple case of option pricing when I discovered this strange behavior. After adding an extra conditional statement, the performance of the function actually become faster. This is som…

---

## [Automatically parameterizing a type](https://discourse.julialang.org/t/automatically-parameterizing-a-type/15945)

<div class="topic-metadata">

**Author:** [@fabgrei](https://discourse.julialang.org/u/fabgrei)\
**Replies:** 9\
**Last updated:** [October 8, 2018, 8:15pm UTC](https://discourse.julialang.org/t/automatically-parameterizing-a-type/15945 "2018-10-08T20:15:41Z")

</div>

In order to achieve good performance one is supposed to use parametric types. Is there a way to do this automatically? I want this @parameterize struct Foo field1::Real field2::AbstractVector field3::Number en…

---

## [Zeros slower than Array comprehension](https://discourse.julialang.org/t/zeros-slower-than-array-comprehension/15980)

<div class="topic-metadata">

**Author:** [@antcap96](https://discourse.julialang.org/u/antcap96)\
**Replies:** 3\
**Last updated:** [October 7, 2018, 1:37am UTC](https://discourse.julialang.org/t/zeros-slower-than-array-comprehension/15980 "2018-10-07T01:37:02Z")

</div>

When testing some things in the REPL I tried creating a 100x100 matrix of zeros and found it strange that the built-in zeros was slower than creating such a matrix using a Array comprehension. julia\> @btime zeros(Float6…

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

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