# Performance

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

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

**Page:** 123

---

## [Confused with @time result for simple addtion of arrays](https://discourse.julialang.org/t/confused-with-time-result-for-simple-addtion-of-arrays/32834)

<div class="topic-metadata">

**Author:** [@balabi](https://discourse.julialang.org/u/balabi)\
**Replies:** 9\
**Last updated:** [January 2, 2020, 4:43pm UTC](https://discourse.julialang.org/t/confused-with-time-result-for-simple-addtion-of-arrays/32834 "2020-01-02T16:43:33Z")

</div>

Hello, I am new to julia. I just installed the latest julia 1.3.1, and then run several small timings. First I define a=\[1,2,3\] Then timing the first time @time a+a it outputs 0.073568 seconds (231.55 k allocations…

---

## [Optimizing Calculation in Julia compared to C (New to Julia)](https://discourse.julialang.org/t/optimizing-calculation-in-julia-compared-to-c-new-to-julia/32723)

<div class="topic-metadata">

**Author:** [@loki](https://discourse.julialang.org/u/loki)\
**Replies:** 25\
**Last updated:** [January 1, 2020, 10:34pm UTC](https://discourse.julialang.org/t/optimizing-calculation-in-julia-compared-to-c-new-to-julia/32723 "2020-01-01T22:34:13Z")

</div>

Hello, just starting to make the switch to Julia from Matlab/C. I’ve been reading up on the speed advantages of Julia and recognize the power that can be wielded in the right hands. I was hoping I could receive some poin…

---

## [Memory allocation on multiple return values](https://discourse.julialang.org/t/memory-allocation-on-multiple-return-values/32805)

<div class="topic-metadata">

**Author:** [@lucas711642](https://discourse.julialang.org/u/lucas711642)\
**Replies:** 3\
**Last updated:** [December 31, 2019, 4:01am UTC](https://discourse.julialang.org/t/memory-allocation-on-multiple-return-values/32805 "2019-12-31T04:01:56Z")

</div>

Is there any way to avoid allocations on functions that return multiple values, when some of these values are mutable? For example: julia\> x = \[0\]; julia\> fun1(x) = @time((x, 1)); julia\> fun2(x) = (fun1(x); nothing); j…

---

## [Type-stable Array of NamedTuples](https://discourse.julialang.org/t/type-stable-array-of-namedtuples/32743)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 12\
**Last updated:** [December 27, 2019, 9:21pm UTC](https://discourse.julialang.org/t/type-stable-array-of-namedtuples/32743 "2019-12-27T21:21:57Z")

</div>

I often want to do the following for a large n where I perform some calculations and return a tuple of values with the result of each iteration: function f(n::Int) v = Vector() for i in 1:n ... push!(v, (a=…

---

## [Julia 1.3 order of magnitude slowdown in function](https://discourse.julialang.org/t/julia-1-3-order-of-magnitude-slowdown-in-function/32691)

<div class="topic-metadata">

**Author:** [@joshua\_jones](https://discourse.julialang.org/u/joshua_jones)\
**Replies:** 1\
**Last updated:** [December 25, 2019, 1:19pm UTC](https://discourse.julialang.org/t/julia-1-3-order-of-magnitude-slowdown-in-function/32691 "2019-12-25T13:19:59Z")

</div>

Cross-posted from https://github.com/JuliaLang/julia/issues/34195 I’m noticing an order-of-magnitude slowdown in a custom function to parse “sample list” files (one ASCII value per line) to Float32 arrays. Any ideas wha…

---

## [Multithreading and fetch() type stability](https://discourse.julialang.org/t/multithreading-and-fetch-type-stability/32465)

<div class="topic-metadata">

**Author:** [@cshen](https://discourse.julialang.org/u/cshen)\
**Replies:** 11\
**Last updated:** [December 23, 2019, 8:30pm UTC](https://discourse.julialang.org/t/multithreading-and-fetch-type-stability/32465 "2019-12-23T20:30:42Z")

</div>

Hello, I was poking around at the new @spawn macro and multithreading in general. I did a @code\_warntype on a function were i’d set up some task with t = @spawn fun(args). The signature of fun is (n::Int)::Int in the …

---

## [Allocations with anonymous functions](https://discourse.julialang.org/t/allocations-with-anonymous-functions/32564)

<div class="topic-metadata">

**Author:** [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Replies:** 4\
**Last updated:** [December 21, 2019, 10:56pm UTC](https://discourse.julialang.org/t/allocations-with-anonymous-functions/32564 "2019-12-21T22:56:02Z")

</div>

I was experimenting with StaticArrays.jl, and noticed the following issue with memory allocations. Consider the following example code: using Random using StaticArrays function f1(X, h, D) Y = D.\*X- h; return …

---

## [Performance of Float32 exponential](https://discourse.julialang.org/t/performance-of-float32-exponential/32549)

<div class="topic-metadata">

**Author:** [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Replies:** 4\
**Last updated:** [December 21, 2019, 3:07pm UTC](https://discourse.julialang.org/t/performance-of-float32-exponential/32549 "2019-12-21T15:07:28Z")

</div>

@LaurentPlagne and myself recently noticed the following surprising performances: julia\> using BenchmarkTools julia\> N = 100\_000 julia\> x32 = rand(Float32, N); julia\> x64 = Float64.(x32); julia\> sumExpStd(x) = sum(exp,…

---

## [Can this loop be optimized further?](https://discourse.julialang.org/t/can-this-loop-be-optimized-further/32510)

<div class="topic-metadata">

**Author:** [@Dictino](https://discourse.julialang.org/u/Dictino)\
**Replies:** 7\
**Last updated:** [December 20, 2019, 2:51pm UTC](https://discourse.julialang.org/t/can-this-loop-be-optimized-further/32510 "2019-12-20T14:51:01Z")

</div>

I have this function to find an element in an array: function my\_findfirst(element,array) for i=1:length(array) if @inbounds (array\[i\]==element) return i end end return nothing end I’ve created thi…

---

## [Differences in collecting algebraic terms or not](https://discourse.julialang.org/t/differences-in-collecting-algebraic-terms-or-not/32488)

<div class="topic-metadata">

**Author:** [@Donkeyfish87](https://discourse.julialang.org/u/Donkeyfish87)\
**Replies:** 5\
**Last updated:** [December 19, 2019, 9:34pm UTC](https://discourse.julialang.org/t/differences-in-collecting-algebraic-terms-or-not/32488 "2019-12-19T21:34:11Z")

</div>

Why is there a difference between function sum\_of\_squares(n::Int) div(n\*(n+1)\*(2n+1), 6) end function square\_of\_sum(n::Int) div(n\*(n+1),2)^2 end function difference(n::Int) square\_of\_sum(n) - sum\_of\_square…

---

## [Efficient way to update a DataFrame stored in a bson file](https://discourse.julialang.org/t/efficient-way-to-update-a-dataframe-stored-in-a-bson-file/32482)

<div class="topic-metadata">

**Author:** [@fipelle](https://discourse.julialang.org/u/fipelle)\
**Replies:** 3\
**Last updated:** [December 19, 2019, 8:30pm UTC](https://discourse.julialang.org/t/efficient-way-to-update-a-dataframe-stored-in-a-bson-file/32482 "2019-12-19T20:30:13Z")

</div>

Hi, I have two DataFrames: df and new\_df. These DataFrames have the same structure (i.e., the same columns). df is stored in a bson file and new\_df is computed by some code. I was wondering what is the most efficient w…

---

## [Are functions the same as closures in this case?](https://discourse.julialang.org/t/are-functions-the-same-as-closures-in-this-case/32467)

<div class="topic-metadata">

**Author:** [@rvignolo](https://discourse.julialang.org/u/rvignolo)\
**Replies:** 8\
**Last updated:** [December 19, 2019, 12:28pm UTC](https://discourse.julialang.org/t/are-functions-the-same-as-closures-in-this-case/32467 "2019-12-19T12:28:10Z")

</div>

Are these functions/closures examples: function main() a = 1.0 b = 5.0 function f1(t) return a \* t + b end f2(t) = a \* t + b f3 = t -\> a \* t + b solver(f1, f2, f3) return nothing end the same w…

---

## [Writing effective parallel code](https://discourse.julialang.org/t/writing-effective-parallel-code/32407)

<div class="topic-metadata">

**Author:** [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Replies:** 8\
**Last updated:** [December 18, 2019, 4:38am UTC](https://discourse.julialang.org/t/writing-effective-parallel-code/32407 "2019-12-18T04:38:41Z")

</div>

I’m trying to think more seriously about writing Julia code that is either thread or worker parallel to make better use of high thread machines or individual cluster nodes with many CPUs. While I recognize that in genera…

---

## [Example for the Depth first multithread implementation performance gain as a motivation](https://discourse.julialang.org/t/example-for-the-depth-first-multithread-implementation-performance-gain-as-a-motivation/32328)

<div class="topic-metadata">

**Author:** [@stakaz](https://discourse.julialang.org/u/stakaz)\
**Replies:** 3\
**Last updated:** [December 16, 2019, 3:12pm UTC](https://discourse.julialang.org/t/example-for-the-depth-first-multithread-implementation-performance-gain-as-a-motivation/32328 "2019-12-16T15:12:57Z")

</div>

Hello, I have found the following discussion on Julias multithread task scheduler implementation: https://news.ycombinator.com/item?id=20507628 As far as I can read from the comments, the main advantage and the “new th…

---

## [Keeping threads busy with 1.3 multiprocessing](https://discourse.julialang.org/t/keeping-threads-busy-with-1-3-multiprocessing/32253)

<div class="topic-metadata">

**Author:** [@babazaroni](https://discourse.julialang.org/u/babazaroni)\
**Replies:** 10\
**Last updated:** [December 16, 2019, 12:37am UTC](https://discourse.julialang.org/t/keeping-threads-busy-with-1-3-multiprocessing/32253 "2019-12-16T00:37:23Z")

</div>

I’m filtering 185 large historical monthly csv files and am allocating a thread to process a month. When I make an initial 185 thread requests, the system starts out allocating all available threads (8 on my machine) bu…

---

## [Why is there a performance hit on broadcasting with OffsetArrays?](https://discourse.julialang.org/t/why-is-there-a-performance-hit-on-broadcasting-with-offsetarrays/32194)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 3\
**Last updated:** [December 15, 2019, 3:20pm UTC](https://discourse.julialang.org/t/why-is-there-a-performance-hit-on-broadcasting-with-offsetarrays/32194 "2019-12-15T15:20:42Z")

</div>

Please have a look at this example: julia\> a = zeros(3,3); b = zeros(1:3,1:3); julia\> @btime @. $a + $a; 49.681 ns (1 allocation: 160 bytes) julia\> @btime @. $b + $b; 440.101 ns (4 allocations: 288 bytes) julia\> …

---

## [Best way to store integer partitions](https://discourse.julialang.org/t/best-way-to-store-integer-partitions/32276)

<div class="topic-metadata">

**Author:** [@Tqft](https://discourse.julialang.org/u/Tqft)\
**Replies:** 6\
**Last updated:** [December 15, 2019, 9:04am UTC](https://discourse.julialang.org/t/best-way-to-store-integer-partitions/32276 "2019-12-15T09:04:23Z")

</div>

This is just a toy example but I was wondering what the best (memory and performance wise) way is to store partitions of a fixed integer n, i.e. lists of positive integers which sum up to n. Currently, I’m using Array{I…

---

## [Simple challenge: Is there a more "Julian" solution?](https://discourse.julialang.org/t/simple-challenge-is-there-a-more-julian-solution/32211)

<div class="topic-metadata">

**Author:** [@wsphillips](https://discourse.julialang.org/u/wsphillips)\
**Replies:** 12\
**Last updated:** [December 13, 2019, 1:51pm UTC](https://discourse.julialang.org/t/simple-challenge-is-there-a-more-julian-solution/32211 "2019-12-13T13:51:55Z")

</div>

I am porting someone else’s MATLAB code and found an indexing pattern that was baked in rather than generated programmatically. After hacking at it for a bit I managed to generalize the pattern. My solution isn’t very pr…

---

## [Optimize benchmark-code](https://discourse.julialang.org/t/optimize-benchmark-code/32105)

<div class="topic-metadata">

**Author:** [@Johannes](https://discourse.julialang.org/u/Johannes)\
**Replies:** 11\
**Last updated:** [December 10, 2019, 8:25pm UTC](https://discourse.julialang.org/t/optimize-benchmark-code/32105 "2019-12-10T20:25:31Z")

</div>

Hey all, I found this benchmark comparing different languages in economics and I wonder whether the underlying Julia code can be optimized further (full repository is available here): ## Basic RBC model with full deprec…

---

## [haskey(Dict) allocates when key is a struct](https://discourse.julialang.org/t/haskey-dict-allocates-when-key-is-a-struct/32093)

<div class="topic-metadata">

**Author:** [@kuba](https://discourse.julialang.org/u/kuba)\
**Replies:** 4\
**Last updated:** [December 10, 2019, 12:52pm UTC](https://discourse.julialang.org/t/haskey-dict-allocates-when-key-is-a-struct/32093 "2019-12-10T12:52:30Z")

</div>

Hi! I’ve noticed that if a key in a Dict is a structure, the haskey function allocates memory: d = Dict{Int64, Int64}() @allocated haskey(d, 0) # 0 when key is an Int struct Key value :: Int64 end d = Dict{Key,…

---

## [Specifying that a function which can take a vector or scalar as input](https://discourse.julialang.org/t/specifying-that-a-function-which-can-take-a-vector-or-scalar-as-input/32042)

<div class="topic-metadata">

**Author:** [@gobs](https://discourse.julialang.org/u/gobs)\
**Replies:** 4\
**Last updated:** [December 9, 2019, 4:04pm UTC](https://discourse.julialang.org/t/specifying-that-a-function-which-can-take-a-vector-or-scalar-as-input/32042 "2019-12-09T16:04:38Z")

</div>

I frequently find myself writing functions which are fundamentally not that different for scalars or vectors. Take this for example: julia\> function silly\_print(x) for i = 1:length(x) println(x\[i\]) end e…

---

## [How to specify that a function which has several (but a limited amount) of possible types as inputs and outputs?](https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041)

<div class="topic-metadata">

**Author:** [@gobs](https://discourse.julialang.org/u/gobs)\
**Replies:** 2\
**Last updated:** [December 9, 2019, 11:02am UTC](https://discourse.julialang.org/t/how-to-specify-that-a-function-which-has-several-but-a-limited-amount-of-possible-types-as-inputs-and-outputs/32041 "2019-12-09T11:02:04Z")

</div>

My code for formulating a specific JuMP optimisation model has started getting quite slow, and I would like to start optimising it by specifying types. One of the main functions I call just searches through two dictiona…

---

## [Tables package for fast grouping and filtering?](https://discourse.julialang.org/t/tables-package-for-fast-grouping-and-filtering/31950)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 18\
**Last updated:** [December 8, 2019, 6:40am UTC](https://discourse.julialang.org/t/tables-package-for-fast-grouping-and-filtering/31950 "2019-12-08T06:40:10Z")

</div>

I already use Julia for much of my simulation and model calibration work, but am considering using it for some of the more basic data preparation I do. This work is primarly filtering, grouping, and applying time series…

---

## [sum(Array{Bool,1}) vs sum(Array(Int8,1})](https://discourse.julialang.org/t/sum-array-bool-1-vs-sum-array-int8-1/31353)

<div class="topic-metadata">

**Author:** [@recri](https://discourse.julialang.org/u/recri)\
**Replies:** 6\
**Last updated:** [December 8, 2019, 3:43am UTC](https://discourse.julialang.org/t/sum-array-bool-1-vs-sum-array-int8-1/31353 "2019-12-08T03:43:56Z")

</div>

I was reviewing old discussions around efficiency and I noticed that summing an array of Bool is still slower (julia-1.3.0-rc5) than summing the same array of values as Int8, which is puzzling since it seems it should in…

---

## [Setfield! allocates memory when setting Float64 values](https://discourse.julialang.org/t/setfield-allocates-memory-when-setting-float64-values/31811)

<div class="topic-metadata">

**Author:** [@MartinOtter](https://discourse.julialang.org/u/MartinOtter)\
**Replies:** 4\
**Last updated:** [December 6, 2019, 11:09am UTC](https://discourse.julialang.org/t/setfield-allocates-memory-when-setting-float64-values/31811 "2019-12-06T11:09:28Z")

</div>

The task is to copy all elements of a vector (x::Vector{Float64}) into a hierarchical data structure many times. Hereby the mapping is fixed at the beginning. For example x\[3\] is always copied to a.b.c.d. Intuitively, it…

---

## [Linear algebra/algorithm: possible speed up for summing up matrices commutators](https://discourse.julialang.org/t/linear-algebra-algorithm-possible-speed-up-for-summing-up-matrices-commutators/31912)

<div class="topic-metadata">

**Author:** [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)\
**Replies:** 1\
**Last updated:** [December 5, 2019, 5:52pm UTC](https://discourse.julialang.org/t/linear-algebra-algorithm-possible-speed-up-for-summing-up-matrices-commutators/31912 "2019-12-05T17:52:29Z")

</div>

With matrix commutator \[A,B\] \\equiv AB-BA, consider the sum of \\sum\_{i=1}^k \[MF\_i, F\_{k-i+1}\], where M and F\_{j} are known matrices. I’m using something like this that allocate in advance: using LinearAlgebra using Benc…

---

## [Type annotation make JIT compile faster?](https://discourse.julialang.org/t/type-annotation-make-jit-compile-faster/31906)

<div class="topic-metadata">

**Author:** [@AtsushiSakai](https://discourse.julialang.org/u/AtsushiSakai)\
**Replies:** 2\
**Last updated:** [December 5, 2019, 2:11pm UTC](https://discourse.julialang.org/t/type-annotation-make-jit-compile-faster/31906 "2019-12-05T14:11:11Z")

</div>

I have a very simple question about Julia itself. Does type annotation for function make JIT compile faster? In other words, Should I add type annotations as much as possible for good JIT compile performance? Best

---

## [Writing functions for types defined in another module](https://discourse.julialang.org/t/writing-functions-for-types-defined-in-another-module/31895)

<div class="topic-metadata">

**Author:** [@jlbosse](https://discourse.julialang.org/u/jlbosse)\
**Replies:** 5\
**Last updated:** [December 5, 2019, 11:51am UTC](https://discourse.julialang.org/t/writing-functions-for-types-defined-in-another-module/31895 "2019-12-05T11:51:51Z")

</div>

I want to have type definitions in one module module1 and then write functions that operate on my type in another module module2 and use these functions and the type in my main script / REPL. But in my current setup I th…

---

## [How to debug compilation time and loading time of packages?](https://discourse.julialang.org/t/how-to-debug-compilation-time-and-loading-time-of-packages/31583)

<div class="topic-metadata">

**Author:** [@jonas-schulze](https://discourse.julialang.org/u/jonas-schulze)\
**Replies:** 4\
**Last updated:** [December 4, 2019, 7:33pm UTC](https://discourse.julialang.org/t/how-to-debug-compilation-time-and-loading-time-of-packages/31583 "2019-12-04T19:33:50Z")

</div>

While waiting for general improvements in compile and load times (cf. comment in Roadmap for a faster time-to-first-plot? - #199 by ChrisRackauckas), what else can we do to improve the user experience for the packages we…

---

## [A cluster config for julia parallel computing](https://discourse.julialang.org/t/a-cluster-config-for-julia-parallel-computing/31723)

<div class="topic-metadata">

**Author:** [@DJRahim](https://discourse.julialang.org/u/DJRahim)\
**Replies:** 1\
**Last updated:** [December 1, 2019, 10:21pm UTC](https://discourse.julialang.org/t/a-cluster-config-for-julia-parallel-computing/31723 "2019-12-01T22:21:17Z")

</div>

Hello, I’m getting started with julia parallel computing and i need to test a parallel algorithm in a cluster, my question is what is the best cluster environment for julia parallel computing and what is the configurat…

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

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