# Performance

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

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

**Page:** 146

---

## [Faster join()?](https://discourse.julialang.org/t/faster-join/7957)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 4\
**Last updated:** [December 25, 2017, 9:26am UTC](https://discourse.julialang.org/t/faster-join/7957 "2017-12-25T09:26:17Z")

</div>

I happened to have no access to Internet this morning and didn’t remember the function that joins strings together. I’m a newbie, clearly :slightly\_smiling\_face: So I wrote my own: concatenate(strArray::Vector{String}…

---

## [Toward faster Rationals](https://discourse.julialang.org/t/toward-faster-rationals/7933)

<div class="topic-metadata">

**Author:** [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)\
**Replies:** 9\
**Last updated:** [December 24, 2017, 1:38am UTC](https://discourse.julialang.org/t/toward-faster-rationals/7933 "2017-12-24T01:38:45Z")

</div>

Consider (abs, inv, +, -, \*, //) over values of type Rational{I} where I\<:Union{Int16…Int128, BigInt}. A substantive time sink is renormalizing the (numerator, denominator) pairs: div each by their gcd. Use two sor…

---

## [Julia slow with Hilbert matrices](https://discourse.julialang.org/t/julia-slow-with-hilbert-matrices/7905)

<div class="topic-metadata">

**Author:** [@jmichel](https://discourse.julialang.org/u/jmichel)\
**Replies:** 9\
**Last updated:** [December 22, 2017, 7:17am UTC](https://discourse.julialang.org/t/julia-slow-with-hilbert-matrices/7905 "2017-12-22T07:17:05Z")

</div>

Hello, I am new to Julia, which I learn in the hope to port some mathematical software (group theory and arithmetic) to. I did a simple test with Hilbert matrices, and to my disappointment I found that on th…

---

## [Workflow for monitoring native code size](https://discourse.julialang.org/t/workflow-for-monitoring-native-code-size/7897)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 11\
**Last updated:** [December 21, 2017, 9:17pm UTC](https://discourse.julialang.org/t/workflow-for-monitoring-native-code-size/7897 "2017-12-21T21:17:06Z")

</div>

A good measure of performance is length of generated machine code. As a package writer, I would like to monitor how well the functions I am writing are in terms of concise assembly. This would improve the performance of …

---

## [How to pre-allocate matrices to avoid constructing new matrices during the for-loop?](https://discourse.julialang.org/t/how-to-pre-allocate-matrices-to-avoid-constructing-new-matrices-during-the-for-loop/7866)

<div class="topic-metadata">

**Author:** [@hongyan](https://discourse.julialang.org/u/hongyan)\
**Replies:** 6\
**Last updated:** [December 20, 2017, 11:17am UTC](https://discourse.julialang.org/t/how-to-pre-allocate-matrices-to-avoid-constructing-new-matrices-during-the-for-loop/7866 "2017-12-20T11:17:00Z")

</div>

Hi guys, I have some codes as follows: function sim(M,R,S,q,numIters,numGrids) for i = 1:numIters tmp = R + reshape(q' \* S, numGrids, numGrids); q = (M - tmp) \\ ((M + tmp) \* q); end return q;…

---

## [Sparse matrix-vector product: much more slow than Matlab](https://discourse.julialang.org/t/sparse-matrix-vector-product-much-more-slow-than-matlab/7840)

<div class="topic-metadata">

**Author:** [@hongyan](https://discourse.julialang.org/u/hongyan)\
**Replies:** 24\
**Last updated:** [December 20, 2017, 10:13am UTC](https://discourse.julialang.org/t/sparse-matrix-vector-product-much-more-slow-than-matlab/7840 "2017-12-20T10:13:56Z")

</div>

Hi guys, I’m very new in Julia and recently I’m doing some sparse matrix-vector calculations and want to transfer to Julia from Matlab. It turns out for the same codes, it takes Matlab about 2 seconds, but about 98 seco…

---

## [Read a text file directly as vector of SVectors](https://discourse.julialang.org/t/read-a-text-file-directly-as-vector-of-svectors/7805)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 6\
**Last updated:** [December 16, 2017, 1:11pm UTC](https://discourse.julialang.org/t/read-a-text-file-directly-as-vector-of-svectors/7805 "2017-12-16T13:11:25Z")

</div>

Here is my try: function read\_dataset(filename, V::Type{SVector{D, T}}, sep::Char = ',') where {D, T} data = SVector{D, T}\[\] open(filename) do io for ss in eachline(io) s = split(ss, sep) …

---

## [Performance with MongoDB ](https://discourse.julialang.org/t/performance-with-mongodb/7577)

<div class="topic-metadata">

**Author:** [@Massimo\_Redaelli](https://discourse.julialang.org/u/Massimo_Redaelli)\
**Replies:** 6\
**Last updated:** [December 15, 2017, 11:49pm UTC](https://discourse.julialang.org/t/performance-with-mongodb/7577 "2017-12-15T23:49:08Z")

</div>

I recently changed job and I am now working in a company doing data science stuff with heavy emphasis on geospatial timeseries. I work with two statisticians that have so far implemented everything in R, and occasionall…

---

## [View way slower than copy?](https://discourse.julialang.org/t/view-way-slower-than-copy/7722)

<div class="topic-metadata">

**Author:** [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Replies:** 7\
**Last updated:** [December 14, 2017, 12:39pm UTC](https://discourse.julialang.org/t/view-way-slower-than-copy/7722 "2017-12-14T12:39:24Z")

</div>

I’m trying to compute the median of a 3D image along the :position axis, but I found copying the slice is way faster than a view? Why is that? The two functions below are identical expect for one has a copy operation ver…

---

## [Memory allocations are not very understandable](https://discourse.julialang.org/t/memory-allocations-are-not-very-understandable/7696)

<div class="topic-metadata">

**Author:** [@rvlander](https://discourse.julialang.org/u/rvlander)\
**Replies:** 26\
**Last updated:** [December 12, 2017, 4:34pm UTC](https://discourse.julialang.org/t/memory-allocations-are-not-very-understandable/7696 "2017-12-12T16:34:28Z")

</div>

I am having a hard time understanding how memory is managed by Julia. Why do the following lines allocate memory at all? - function winsMilestone(topSide, bottomSide, justPlayedCard::Player) 827581056 if (…

---

## [Performant creation of vector of SVectors given a known formula](https://discourse.julialang.org/t/performant-creation-of-vector-of-svectors-given-a-known-formula/7648)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 17\
**Last updated:** [December 11, 2017, 1:22pm UTC](https://discourse.julialang.org/t/performant-creation-of-vector-of-svectors-given-a-known-formula/7648 "2017-12-11T13:22:32Z")

</div>

I want to create a vector of SVectors. I have to create all SVectors on the spot, given a formula that I know, and given also the dimensionality I know. The dimensionality can also be type-parameter, there is no problem …

---

## [Is \`Vector{UInt8}(string)\` the fastest way to convert String to bytes?](https://discourse.julialang.org/t/is-vector-uint8-string-the-fastest-way-to-convert-string-to-bytes/7642)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 19\
**Last updated:** [December 10, 2017, 12:24pm UTC](https://discourse.julialang.org/t/is-vector-uint8-string-the-fastest-way-to-convert-string-to-bytes/7642 "2017-12-10T12:24:30Z")

</div>

Is Vecotr{UInt8}(string) the fastest way to convert String to bytes? From my testing, it seems to perform ok const M = 100\_000\_000; const K = 100 const s = rand(\[@sprintf "id%03d" k for k in 1:K\], M) function ghi(s::Ve…

---

## [Best way to construct a sparse matrix](https://discourse.julialang.org/t/best-way-to-construct-a-sparse-matrix/7657)

<div class="topic-metadata">

**Author:** [@lbittarello](https://discourse.julialang.org/u/lbittarello)\
**Replies:** 3\
**Last updated:** [December 9, 2017, 7:29pm UTC](https://discourse.julialang.org/t/best-way-to-construct-a-sparse-matrix/7657 "2017-12-09T19:29:04Z")

</div>

Hi! I’m writing a function that constructs a symmetric sparse matrix. I’ve tried two implementations: function version1(x::Vector{Date}, k::Function) n = length(x) mat = speye(Float64, n, n) for i = 1:n…

---

## [What's the fastest way to generate \`\[1,2,....,n\]\`?](https://discourse.julialang.org/t/whats-the-fastest-way-to-generate-1-2-n/7564)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 16\
**Last updated:** [December 8, 2017, 6:51pm UTC](https://discourse.julialang.org/t/whats-the-fastest-way-to-generate-1-2-n/7564 "2017-12-08T18:51:52Z")

</div>

For an algorithm I need to generate x = \[1,2,...,n\] for a large n and I can’t do x = 1:n as I need to reassign the values in x so I can do something like x\[10\] = x\[2\]. Currently I am doing x=collect(1:n) and I tested x …

---

## [Help understanding allocation on scalar function and possible ways to avoid it](https://discourse.julialang.org/t/help-understanding-allocation-on-scalar-function-and-possible-ways-to-avoid-it/7614)

<div class="topic-metadata">

**Author:** [@favba](https://discourse.julialang.org/u/favba)\
**Replies:** 3\
**Last updated:** [December 7, 2017, 9:30pm UTC](https://discourse.julialang.org/t/help-understanding-allocation-on-scalar-function-and-possible-ways-to-avoid-it/7614 "2017-12-07T21:30:57Z")

</div>

Can someone kindly explain me why the following function allocates memory? Is there a way to avoid it? On my machine it produces 14 allocations using inputs of Float64s (on Julia 6.1). julia\> using BenchmarkTools juli…

---

## [Allocation - groupby](https://discourse.julialang.org/t/allocation-groupby/7505)

<div class="topic-metadata">

**Author:** [@rojo](https://discourse.julialang.org/u/rojo)\
**Replies:** 5\
**Last updated:** [December 5, 2017, 12:11am UTC](https://discourse.julialang.org/t/allocation-groupby/7505 "2017-12-05T00:11:42Z")

</div>

I’m attempting to create a function groupby(f, itr) that returns a dictionary whose keys are the results of applying f to the elements of itr, and the values are some collection of the elements themselves. Similar to Mat…

---

## [Using @inbounds](https://discourse.julialang.org/t/using-inbounds/7499)

<div class="topic-metadata">

**Author:** [@drjoke](https://discourse.julialang.org/u/drjoke)\
**Replies:** 1\
**Last updated:** [December 4, 2017, 4:34pm UTC](https://discourse.julialang.org/t/using-inbounds/7499 "2017-12-04T16:34:43Z")

</div>

@inbounds for j = 1:networks\_hidden\_layer\_size\[1\] hidden\_sums\[j, 1, s, y, n\] = 0 for i = 1:networks\_input\_count\[1\] hidden\_sums\[j, 1, s, y, n\] += networks\_in…

---

## [View into HDF5 dataset](https://discourse.julialang.org/t/view-into-hdf5-dataset/7495)

<div class="topic-metadata">

**Author:** [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Replies:** 1\
**Last updated:** [December 4, 2017, 4:10pm UTC](https://discourse.julialang.org/t/view-into-hdf5-dataset/7495 "2017-12-04T16:10:59Z")

</div>

Is it possible, for writing, to get a “view” into part of a HDF5 dataset containing an array of some dimension? I have a HDF5 file with some dataset, let’s say, data, where data is an array of some dimension. I want to …

---

## [A generator with two "for" keywords is slow](https://discourse.julialang.org/t/a-generator-with-two-for-keywords-is-slow/7407)

<div class="topic-metadata">

**Author:** [@Jan\_Dolinsky](https://discourse.julialang.org/u/Jan_Dolinsky)\
**Replies:** 14\
**Last updated:** [December 4, 2017, 3:53pm UTC](https://discourse.julialang.org/t/a-generator-with-two-for-keywords-is-slow/7407 "2017-12-04T15:53:07Z")

</div>

Hello, I create a vector of vectors as follows. v = map(rand, fill(10^4, 5)); I want to compute a mean of all the elements in all 5 vectors, i.e. flattening the “v”. I approached this in the following three different …

---

## [Trying PkgBenchmark.jl again](https://discourse.julialang.org/t/trying-pkgbenchmark-jl-again/7429)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 5\
**Last updated:** [December 1, 2017, 5:34pm UTC](https://discourse.julialang.org/t/trying-pkgbenchmark-jl-again/7429 "2017-12-01T17:34:15Z")

</div>

I got to a point where I need to keep track of performance improvements in my packages, specially with new releases of Julia coming up. The PkgBenchmark.jl package proposes a nice interface similar to Base.Test for bench…

---

## [Unsafe\_store! sometimes slower than arrays' setindex!?](https://discourse.julialang.org/t/unsafe-store-sometimes-slower-than-arrays-setindex/7166)

<div class="topic-metadata">

**Author:** [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Replies:** 15\
**Last updated:** [November 30, 2017, 4:45pm UTC](https://discourse.julialang.org/t/unsafe-store-sometimes-slower-than-arrays-setindex/7166 "2017-11-30T16:45:37Z")

</div>

While trying to fix the FIXMEs in “base/random/RNGs.jl”, I saw performance degraded in a very unexpected way. Basically it amounts to the following benchmark. I would be grateful if someone can point to me a workaround w…

---

## [Thread overhead variability across machines](https://discourse.julialang.org/t/thread-overhead-variability-across-machines/7320)

<div class="topic-metadata">

**Author:** [@alee](https://discourse.julialang.org/u/alee)\
**Replies:** 13\
**Last updated:** [November 28, 2017, 11:51pm UTC](https://discourse.julialang.org/t/thread-overhead-variability-across-machines/7320 "2017-11-28T23:51:14Z")

</div>

I am being hit by large overheads associated with running Threads.@threads for on one machine, and I don’t understand the source of the issue. Here is minimal working example code in a file called threadOverhead.jl usin…

---

## [Memory hog when using include() in a for loop](https://discourse.julialang.org/t/memory-hog-when-using-include-in-a-for-loop/7235)

<div class="topic-metadata">

**Author:** [@jac0320](https://discourse.julialang.org/u/jac0320)\
**Replies:** 0\
**Last updated:** [November 21, 2017, 11:14pm UTC](https://discourse.julialang.org/t/memory-hog-when-using-include-in-a-for-loop/7235 "2017-11-21T23:14:14Z")

</div>

I was trying to load a bunch of JuMP optimization models by including(include/evalfile) a model script in a for loop. A simple example: for i in 1:1000 m = include("o7.jl") end This loop seem to have an accumulating …

---

## [Making use of precompile](https://discourse.julialang.org/t/making-use-of-precompile/7171)

<div class="topic-metadata">

**Author:** [@Mattes](https://discourse.julialang.org/u/Mattes)\
**Replies:** 1\
**Last updated:** [November 19, 2017, 7:00pm UTC](https://discourse.julialang.org/t/making-use-of-precompile/7171 "2017-11-19T19:00:19Z")

</div>

I have a very simple program using ArgParse.jl: using ArgParse function main(args) s = ArgParseSettings(description = "Example 1 for argparse.jl: minimal usage.") @add\_arg\_table s begin "--max\_n", "-N"…

---

## [Performance of Julia as a general-purpose programming language](https://discourse.julialang.org/t/performance-of-julia-as-a-general-purpose-programming-language/6995)

<div class="topic-metadata">

**Author:** [@juliendehos](https://discourse.julialang.org/u/juliendehos)\
**Replies:** 30\
**Last updated:** [November 19, 2017, 10:28am UTC](https://discourse.julialang.org/t/performance-of-julia-as-a-general-purpose-programming-language/6995 "2017-11-19T10:28:56Z")

</div>

Hi, I used Julia for a “computing” project recently and it was really nice. Now, I’m tempted to use Julia for a more “classic” project (involving tree-like data-structures) so I’ve implemented a test project (the tictac…

---

## [Understanding type stability](https://discourse.julialang.org/t/understanding-type-stability/6953)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)\
**Replies:** 16\
**Last updated:** [November 16, 2017, 10:12am UTC](https://discourse.julialang.org/t/understanding-type-stability/6953 "2017-11-16T10:12:04Z")

</div>

For my FEM work, I want to be able to multiply higher dimension arrays with each other, as in “cartensian tensors”. I know there are packages, I want to learn. Function dots2 is specialised to multiply 3-Arrays with ve…

---

## [Is the increasing slowness of LLVM compilation a worry?](https://discourse.julialang.org/t/is-the-increasing-slowness-of-llvm-compilation-a-worry/7023)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 8\
**Last updated:** [November 12, 2017, 2:17pm UTC](https://discourse.julialang.org/t/is-the-increasing-slowness-of-llvm-compilation-a-worry/7023 "2017-11-12T14:17:51Z")

</div>

I have heard many-a-times that LLVM is slow when it comes to compilation; I heard it in relations to why Go did not choose LLVM, and Rust having long compilation times, and this video where Jeff Bezanson talks about LLVM…

---

## [Two or more @threads for blocks in the same function](https://discourse.julialang.org/t/two-or-more-threads-for-blocks-in-the-same-function/6999)

<div class="topic-metadata">

**Author:** [@alee](https://discourse.julialang.org/u/alee)\
**Replies:** 1\
**Last updated:** [November 10, 2017, 11:01pm UTC](https://discourse.julialang.org/t/two-or-more-threads-for-blocks-in-the-same-function/6999 "2017-11-10T23:01:47Z")

</div>

First off, I am very impressed with multi-threading so far, although I am mainly treating @threads for as basic OpenMP parallel regions. This question is more related to my having to create extra small functions to avoid…

---

## [Type stability, deprecation](https://discourse.julialang.org/t/type-stability-deprecation/6822)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon](https://discourse.julialang.org/u/Philippe_Maincon)\
**Replies:** 4\
**Last updated:** [November 8, 2017, 8:27am UTC](https://discourse.julialang.org/t/type-stability-deprecation/6822 "2017-11-08T08:27:37Z")

</div>

Hi, Below, I have an extract of code that does a) automatic differentiation (I know, ForwardDiff.jl does it better, but I want to learn) and b) some “tensor” operation. Running the same test on plain old Float64 is f…

---

## [Broadcasting assignment idea](https://discourse.julialang.org/t/broadcasting-assignment-idea/6918)

<div class="topic-metadata">

**Author:** [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Replies:** 0\
**Last updated:** [November 6, 2017, 9:34pm UTC](https://discourse.julialang.org/t/broadcasting-assignment-idea/6918 "2017-11-06T21:34:06Z")

</div>

Given A::AbstractMatrix and b::AbstractVector one can broadcast assignments like: A\[:,cols\] .= b.' where cols may be a container of valid indices… However, I would like to broadcast assignment where cols is, WLOG, Vect…

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

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