# Performance

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

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

**Page:** 138

---

## [Making high performance functions with flexible inputs](https://discourse.julialang.org/t/making-high-performance-functions-with-flexible-inputs/15890)

<div class="topic-metadata">

**Author:** [@joshdorrington](https://discourse.julialang.org/u/joshdorrington)\
**Replies:** 1\
**Last updated:** [October 4, 2018, 7:28pm UTC](https://discourse.julialang.org/t/making-high-performance-functions-with-flexible-inputs/15890 "2018-10-04T19:28:10Z")

</div>

I’m writing some code to solve a couple of o.d.e systems I’m working with. At the moment I have some code that looks like this: function timestep\_a(init;T=1.,dt=0.0005) for t in 0.:dt:T …

---

## [General reduction performance](https://discourse.julialang.org/t/general-reduction-performance/15675)

<div class="topic-metadata">

**Author:** [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Replies:** 4\
**Last updated:** [October 3, 2018, 7:59am UTC](https://discourse.julialang.org/t/general-reduction-performance/15675 "2018-10-03T07:59:43Z")

</div>

I need to efficiently apply a custom reduction function along specific axis of a large array, basically what mapslices does. However the performance is 30 times worse than expected: using BenchmarkTools using Statistic…

---

## [Iterating over cols, vcat, repeat?](https://discourse.julialang.org/t/iterating-over-cols-vcat-repeat/15659)

<div class="topic-metadata">

**Author:** [@qsong](https://discourse.julialang.org/u/qsong)\
**Replies:** 7\
**Last updated:** [October 2, 2018, 8:23am UTC](https://discourse.julialang.org/t/iterating-over-cols-vcat-repeat/15659 "2018-10-02T08:23:38Z")

</div>

I come from R world here for performance. @time shows that (123.55 k allocations: 6.260 MiB) for the below code. It seems more allocations than my expectation. So I was wondering if there be some improvement with the cod…

---

## [Crash using Channels/Conditions with @threads](https://discourse.julialang.org/t/crash-using-channels-conditions-with-threads/15730)

<div class="topic-metadata">

**Author:** [@orenbenkiki](https://discourse.julialang.org/u/orenbenkiki)\
**Replies:** 2\
**Last updated:** [October 2, 2018, 6:43am UTC](https://discourse.julialang.org/t/crash-using-channels-conditions-with-threads/15730 "2018-10-02T06:43:28Z")

</div>

Following up on Recommended way to do work stealing in Julia, I have tried writing a small scheduler myself and uploaded it to Github. The scheduler itself isn’t the point of the project - it is meant to be an internal …

---

## [Performance regression in 1.0.1](https://discourse.julialang.org/t/performance-regression-in-1-0-1/15763)

<div class="topic-metadata">

**Author:** [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Replies:** 5\
**Last updated:** [October 2, 2018, 3:28am UTC](https://discourse.julialang.org/t/performance-regression-in-1-0-1/15763 "2018-10-02T03:28:43Z")

</div>

One of my programs which took 1mn on 1.0.0 takes 5mn on 1.0.1 I tracked at least part of the problem to the following code snippet: function foo(gens,elts::Vararg{Vector{Int}}) ee=collect(elts) for i in eachindex(g…

---

## [Iterating over two vectors with vcat is faster than Iterators.flatten and CatViews?](https://discourse.julialang.org/t/iterating-over-two-vectors-with-vcat-is-faster-than-iterators-flatten-and-catviews/15698)

<div class="topic-metadata">

**Author:** [@control13](https://discourse.julialang.org/u/control13)\
**Replies:** 10\
**Last updated:** [October 1, 2018, 4:07pm UTC](https://discourse.julialang.org/t/iterating-over-two-vectors-with-vcat-is-faster-than-iterators-flatten-and-catviews/15698 "2018-10-01T16:07:14Z")

</div>

Hey, I have two independant vectors, which change in size over time, but sometimes I need to iterate over them both. I tried vcat, Iterators.flatten and CatViews and vcat needs the least amount of runtime and memory, qu…

---

## [Are Julia Arrays double pointers?](https://discourse.julialang.org/t/are-julia-arrays-double-pointers/15732)

<div class="topic-metadata">

**Author:** [@jacob](https://discourse.julialang.org/u/jacob)\
**Replies:** 8\
**Last updated:** [October 1, 2018, 2:12pm UTC](https://discourse.julialang.org/t/are-julia-arrays-double-pointers/15732 "2018-10-01T14:12:07Z")

</div>

When you have a immutable struct struct A a::Array{Float64, 1} end b = A(\[1,2,3\]) then you can do A.a\[2\] = 5. Ok, I understand that this is possible as you just mutate the object which A.a is pointing to, you do no…

---

## [Whitelist/Blacklist for captured variable](https://discourse.julialang.org/t/whitelist-blacklist-for-captured-variable/15714)

<div class="topic-metadata">

**Author:** [@qsong](https://discourse.julialang.org/u/qsong)\
**Replies:** 3\
**Last updated:** [October 1, 2018, 1:21pm UTC](https://discourse.julialang.org/t/whitelist-blacklist-for-captured-variable/15714 "2018-10-01T13:21:07Z")

</div>

While doing do block, I pay attention to the variables captured by the closure. I tried some example in the manual and the previous discussions (like recent thread ) and found no let needed in some cases. As I don’t know…

---

## [Do for loops capture by reference or by value](https://discourse.julialang.org/t/do-for-loops-capture-by-reference-or-by-value/15708)

<div class="topic-metadata">

**Author:** [@Gregory\_Martinez](https://discourse.julialang.org/u/Gregory_Martinez)\
**Replies:** 9\
**Last updated:** [October 1, 2018, 12:08pm UTC](https://discourse.julialang.org/t/do-for-loops-capture-by-reference-or-by-value/15708 "2018-10-01T12:08:50Z")

</div>

For range for loops in julia, is the element, “elm” in the for loop “for elm in vec ... end” captured by reference or value? In the following test bellow seems in indicate that it is captured by value where I declare a…

---

## [2 identical versions of the code: one allocates the other not, when accessing type-unstable tuple. Why?](https://discourse.julialang.org/t/2-identical-versions-of-the-code-one-allocates-the-other-not-when-accessing-type-unstable-tuple-why/15617)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 3\
**Last updated:** [October 1, 2018, 8:22am UTC](https://discourse.julialang.org/t/2-identical-versions-of-the-code-one-allocates-the-other-not-when-accessing-type-unstable-tuple-why/15617 "2018-10-01T08:22:42Z")

</div>

I am aware that the two versions have to be different somewhere. But where? I Can’t see it. Also, please excuse the “Not Minimal Enough” Minimal Working Example Summary So I am writing a very nice example that highligh…

---

## [Recursive Fibonacci Benchmark using top languages on Github](https://discourse.julialang.org/t/recursive-fibonacci-benchmark-using-top-languages-on-github/15602)

<div class="topic-metadata">

**Author:** [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Replies:** 11\
**Last updated:** [September 29, 2018, 1:38am UTC](https://discourse.julialang.org/t/recursive-fibonacci-benchmark-using-top-languages-on-github/15602 "2018-09-29T01:38:15Z")

</div>

Dear all, this popped up in the hacker news. It uses julia 0.6.3 version. https://github.com/drujensen/fib/blob/master/README.md

---

## [Julia one third slower than ccall-ing \`@code\_native\` assembly compiled with gcc?](https://discourse.julialang.org/t/julia-one-third-slower-than-ccall-ing-code-native-assembly-compiled-with-gcc/12901)

<div class="topic-metadata">

**Author:** [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Replies:** 2\
**Last updated:** [September 29, 2018, 1:18am UTC](https://discourse.julialang.org/t/julia-one-third-slower-than-ccall-ing-code-native-assembly-compiled-with-gcc/12901 "2018-09-29T01:18:45Z")

</div>

I’m working on a series of blog posts about trying to optimize matrix multiplication in Julia. This is on: julia\> versioninfo() Julia Version 1.0.0-DEV.0 Commit ce2aa22d47 (2018-08-02 23:11 UTC) Platform Info: OS: Li…

---

## [Start-up performance, types and compiler's type inference](https://discourse.julialang.org/t/start-up-performance-types-and-compilers-type-inference/15254)

<div class="topic-metadata">

**Author:** [@davidm](https://discourse.julialang.org/u/davidm)\
**Replies:** 5\
**Last updated:** [September 27, 2018, 6:49pm UTC](https://discourse.julialang.org/t/start-up-performance-types-and-compilers-type-inference/15254 "2018-09-27T18:49:52Z")

</div>

I’ve been trying to reduce the start-up time to run a small OpenGL (Modern.jl and GLFW) program. I clearly saw that the compilation part was introducing significant overhead, much more than the actual computations. In f…

---

## [\`eigs\` for sparse tridiagonal matrix: Arpack.jl vs scipy](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566)

<div class="topic-metadata">

**Author:** [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Replies:** 3\
**Last updated:** [September 27, 2018, 4:04pm UTC](https://discourse.julialang.org/t/eigs-for-sparse-tridiagonal-matrix-arpack-jl-vs-scipy/15566 "2018-09-27T16:04:41Z")

</div>

MWE: using LinearAlgebra, SparseArrays, Arpack, PyCall, BenchmarkTools @pyimport scipy.sparse as pysparse @pyimport scipy.sparse.linalg as pylinalg N = 100\_000 X = sparse(Tridiagonal(1.0:N-1, 1.0:N, 1.0:N-1)) X = X + X…

---

## [Combining two arrays with alternating elements](https://discourse.julialang.org/t/combining-two-arrays-with-alternating-elements/15498)

<div class="topic-metadata">

**Author:** [@Gregory\_Martinez](https://discourse.julialang.org/u/Gregory_Martinez)\
**Replies:** 10\
**Last updated:** [September 26, 2018, 1:15pm UTC](https://discourse.julialang.org/t/combining-two-arrays-with-alternating-elements/15498 "2018-09-26T13:15:18Z")

</div>

I wish to combine two arrays, lets say a = \[1, 2, 3, …\] and b = \[4, 5, 6, …\], so that the elements alternate between them like so: c = \[1, 4, 2, 5, 3, 6, …\]. My first attempt was to make an “my\_combine” object like so: …

---

## [Summing arrays efficiently](https://discourse.julialang.org/t/summing-arrays-efficiently/15338)

<div class="topic-metadata">

**Author:** [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Replies:** 9\
**Last updated:** [September 22, 2018, 2:20pm UTC](https://discourse.julialang.org/t/summing-arrays-efficiently/15338 "2018-09-22T14:20:44Z")

</div>

N = 1024 ^ 2; A = \[ones(N), ones(N), ones(N), ones(N)\]; The naive way of summing the arrays in A would be to do sum(A). However, note the performance: julia\> @btime sum(A); 7.968 ms (6 allocations: 24.00 MiB) It unn…

---

## [Help with performance tuning this dataframe aggregation](https://discourse.julialang.org/t/help-with-performance-tuning-this-dataframe-aggregation/15357)

<div class="topic-metadata">

**Author:** [@jonjilla](https://discourse.julialang.org/u/jonjilla)\
**Replies:** 10\
**Last updated:** [September 23, 2018, 5:11pm UTC](https://discourse.julialang.org/t/help-with-performance-tuning-this-dataframe-aggregation/15357 "2018-09-23T17:11:28Z")

</div>

I’ve been working on an application and have narrowed down the piece that appears to be taking the most time. in this following code, it’s generating dataframes d,e,f l = 10000 data = DataFrame(\[Int64, Int64, Int64, In…

---

## [Sum, mapreduce and broadcasted](https://discourse.julialang.org/t/sum-mapreduce-and-broadcasted/15300)

<div class="topic-metadata">

**Author:** [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Replies:** 14\
**Last updated:** [September 23, 2018, 7:57am UTC](https://discourse.julialang.org/t/sum-mapreduce-and-broadcasted/15300 "2018-09-23T07:57:36Z")

</div>

I was trying to sum a broadcasted array without materialising it. Why is this slower? using BenchmarkTools v = rand(100); @btime sum($v .\* $v') ## 9.906 μs (2 allocations: 78.20 KiB) @btime mapreduce(identity, +, Bro…

---

## [Julia 1.0, tight-binding benchmark and array slices](https://discourse.julialang.org/t/julia-1-0-tight-binding-benchmark-and-array-slices/13943)

<div class="topic-metadata">

**Author:** [@jabl](https://discourse.julialang.org/u/jabl)\
**Replies:** 9\
**Last updated:** [September 22, 2018, 7:02pm UTC](https://discourse.julialang.org/t/julia-1-0-tight-binding-benchmark-and-array-slices/13943 "2018-09-22T19:02:37Z")

</div>

Hi, following the recent release of Julia 1.0 I updated a small benchmark tight-binding program that I have implemented in Fortran, C++ with Eigen, C++ with Armadillo, and python/numpy. Roughly, the Fortran and both C++…

---

## [Product of three matrices fast](https://discourse.julialang.org/t/product-of-three-matrices-fast/15339)

<div class="topic-metadata">

**Author:** [@jarl](https://discourse.julialang.org/u/jarl)\
**Replies:** 5\
**Last updated:** [September 22, 2018, 3:11pm UTC](https://discourse.julialang.org/t/product-of-three-matrices-fast/15339 "2018-09-22T15:11:09Z")

</div>

I want to multiply three matrices together as efficiently as possible. We all know that if you have tall and skinny or fat and short matrices, the order of operations when multiplying three matrices matter a lot for eff…

---

## [Write/read multiple arrays of different types 300+ Million elements each. Brute force .jld seems stupid.](https://discourse.julialang.org/t/write-read-multiple-arrays-of-different-types-300-million-elements-each-brute-force-jld-seems-stupid/15229)

<div class="topic-metadata">

**Author:** [@Mikkel-Holm](https://discourse.julialang.org/u/Mikkel-Holm)\
**Replies:** 14\
**Last updated:** [September 21, 2018, 2:09pm UTC](https://discourse.julialang.org/t/write-read-multiple-arrays-of-different-types-300-million-elements-each-brute-force-jld-seems-stupid/15229 "2018-09-21T14:09:22Z")

</div>

I am working with a semi-large dataset consisting of multiple arrays of different types each of ~300 Mil indexes. Using the JLD package to load the data as .jld files takes around 60 minutes, which is simply too slow. W…

---

## [Two Questions About Multithreading](https://discourse.julialang.org/t/two-questions-about-multithreading/14564)

<div class="topic-metadata">

**Author:** [@Juser](https://discourse.julialang.org/u/Juser)\
**Replies:** 5\
**Last updated:** [September 18, 2018, 9:13pm UTC](https://discourse.julialang.org/t/two-questions-about-multithreading/14564 "2018-09-18T21:13:24Z")

</div>

(1) There is some discussion in this old thread about building arrays in a thread-safe way. The solution proposed there is to allocate Threads.nthreads() separate arrays and allow each thread to freely use push! on its o…

---

## [rand(1:10) vs Int(round(10\*rand())](https://discourse.julialang.org/t/rand-1-10-vs-int-round-10-rand/14339)

<div class="topic-metadata">

**Author:** [@mbeach42](https://discourse.julialang.org/u/mbeach42)\
**Replies:** 17\
**Last updated:** [September 18, 2018, 12:32am UTC](https://discourse.julialang.org/t/rand-1-10-vs-int-round-10-rand/14339 "2018-09-18T00:32:07Z")

</div>

Why should I use rand(1:N) for an integer N, instead of Int.(round.(rand()\*N?)) On my computer, it seems that Int.(round.(rand()\*N?)) is about 3 times faster than rand(1:10).

---

## [Backward substitution without memory allocation (Julia v0.6)](https://discourse.julialang.org/t/backward-substitution-without-memory-allocation-julia-v0-6/15060)

<div class="topic-metadata">

**Author:** [@migarstka](https://discourse.julialang.org/u/migarstka)\
**Replies:** 0\
**Last updated:** [September 17, 2018, 11:57am UTC](https://discourse.julialang.org/t/backward-substitution-without-memory-allocation-julia-v0-6/15060 "2018-09-17T11:57:39Z")

</div>

Let’s say I have a sparse positive semidefinite matrix that I want to factor using ldltfact and then solve a system of equations with changing right hand sides. Is there any way to do this without allocating new memory …

---

## [Profile segfault](https://discourse.julialang.org/t/profile-segfault/13484)

<div class="topic-metadata">

**Author:** [@jstrube](https://discourse.julialang.org/u/jstrube)\
**Replies:** 5\
**Last updated:** [September 16, 2018, 9:12pm UTC](https://discourse.julialang.org/t/profile-segfault/13484 "2018-09-16T21:12:33Z")

</div>

I’m porting some particle physics code (Fox Wolfram moments) to Julia. The first attempt had pretty awful performance, so I’m trying to figure out the bottle necks. Unfortunately, profile barfs (trace below). This code…

---

## ['using MyModule' is costly](https://discourse.julialang.org/t/using-mymodule-is-costly/14984)

<div class="topic-metadata">

**Author:** [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Replies:** 6\
**Last updated:** [September 15, 2018, 2:49pm UTC](https://discourse.julialang.org/t/using-mymodule-is-costly/14984 "2018-09-15T14:49:57Z")

</div>

See my experiments below: $ julia \_ \_ \_ \_(\_)\_ | Documentation: https://docs.julialang.org (\_) | (\_) (\_) | \_ \_ \_| |\_ \_\_ \_ | Type "?" for help, "\]?" for Pkg help. | | | | |…

---

## [Multiplication of rational by an integer](https://discourse.julialang.org/t/multiplication-of-rational-by-an-integer/14991)

<div class="topic-metadata">

**Author:** [@Pavel\_Kalouguine](https://discourse.julialang.org/u/Pavel_Kalouguine)\
**Replies:** 0\
**Last updated:** [September 15, 2018, 9:08am UTC](https://discourse.julialang.org/t/multiplication-of-rational-by-an-integer/14991 "2018-09-15T09:08:43Z")

</div>

When profiling some Julia code I stumbled upon an unexpected performance bottleneck at the line corresponding to multiplication of a static matrix of integers and a static vector of rationals. Further investigation revea…

---

## [Simple and fast bisection](https://discourse.julialang.org/t/simple-and-fast-bisection/14886)

<div class="topic-metadata">

**Author:** [@ric.cioffi](https://discourse.julialang.org/u/ric.cioffi)\
**Replies:** 8\
**Last updated:** [September 13, 2018, 5:54pm UTC](https://discourse.julialang.org/t/simple-and-fast-bisection/14886 "2018-09-13T17:54:52Z")

</div>

Hi, as the title says I’m trying to build a simple and fast bisection algorithm. I know the Roots.jl package already implements it, yet I’m doing it both for pedagogical purposes and because I then plan to expand it with…

---

## [Matrix exponential slower in Julia 0.7 / 1.0?](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762)

<div class="topic-metadata">

**Author:** [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Replies:** 7\
**Last updated:** [September 12, 2018, 8:18pm UTC](https://discourse.julialang.org/t/matrix-exponential-slower-in-julia-0-7-1-0/14762 "2018-09-12T20:18:25Z")

</div>

In Julia 0.6.4: julia\> @btime expm(\[1 0; 2 0\]) 3.601 μs (46 allocations: 4.55 KiB) In Julia 0.7 and 1.0: julia\> @btime exp(\[1 0; 2 0\]) 16.710 μs (67 allocations: 4.55 KiB) Any idea what’s causing this? Perhaps th…

---

## [Memory allocation in type construction](https://discourse.julialang.org/t/memory-allocation-in-type-construction/14821)

<div class="topic-metadata">

**Author:** [@retrosnub](https://discourse.julialang.org/u/retrosnub)\
**Replies:** 2\
**Last updated:** [September 11, 2018, 7:58pm UTC](https://discourse.julialang.org/t/memory-allocation-in-type-construction/14821 "2018-09-11T19:58:39Z")

</div>

I’m trying to get rid of memory allocations and reduced my problem to the following: using BenchmarkTools struct A{T} a::T end a = rand(3, 3) @btime A($a) Does anybody know why this allocates 16 bytes and maybe how to …

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

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