# Performance

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

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

**Page:** 147

---

## [Function performance when passed as an argument vs. passed in a struct](https://discourse.julialang.org/t/function-performance-when-passed-as-an-argument-vs-passed-in-a-struct/6703)

<div class="topic-metadata">

**Author:** [@alee](https://discourse.julialang.org/u/alee)\
**Replies:** 8\
**Last updated:** [November 4, 2017, 11:40pm UTC](https://discourse.julialang.org/t/function-performance-when-passed-as-an-argument-vs-passed-in-a-struct/6703 "2017-11-04T23:40:01Z")

</div>

I am new to Julia, but have looked at the manual and searched online, and can’t seem to find the answer to this question. Apologies if I have missed it. Is there a recommended way to package together functions when call…

---

## [Zeroing elements of matrix A depending on matrix B. Fast?](https://discourse.julialang.org/t/zeroing-elements-of-matrix-a-depending-on-matrix-b-fast/6849)

<div class="topic-metadata">

**Author:** [@zenon](https://discourse.julialang.org/u/zenon)\
**Replies:** 19\
**Last updated:** [November 4, 2017, 7:19pm UTC](https://discourse.julialang.org/t/zeroing-elements-of-matrix-a-depending-on-matrix-b-fast/6849 "2017-11-04T19:19:54Z")

</div>

Hi, two matrices A, B, B has a bunch of zero elements, and I need to set A\[i,j\] = 0 wherever B\[i,j\] == 0 I hoped to use that B .!= 0 is a boolean matrix, and try something like (B .!= 0) .&& A but that’s bad syntax …

---

## [@threads vs @parallel, a simple fail case for @threads](https://discourse.julialang.org/t/threads-vs-parallel-a-simple-fail-case-for-threads/6801)

<div class="topic-metadata">

**Author:** [@fkjogu](https://discourse.julialang.org/u/fkjogu)\
**Replies:** 3\
**Last updated:** [October 31, 2017, 6:20pm UTC](https://discourse.julialang.org/t/threads-vs-parallel-a-simple-fail-case-for-threads/6801 "2017-10-31T18:20:27Z")

</div>

I’m new to Julia. I was experimenting with simple parallel code using threads and processes. Why is a = SharedArray{Int64,1}(4) @time @sync @parallel for i = 1:60000000 a\[myid() - 1\] = i end # 1.663024 seconds (7…

---

## [@allocate in REPL, different results, same code](https://discourse.julialang.org/t/allocate-in-repl-different-results-same-code/6756)

<div class="topic-metadata">

**Author:** [@goretkin](https://discourse.julialang.org/u/goretkin)\
**Replies:** 3\
**Last updated:** [October 30, 2017, 12:39am UTC](https://discourse.julialang.org/t/allocate-in-repl-different-results-same-code/6756 "2017-10-30T00:39:23Z")

</div>

function ha(x) return (x, x) end function hs(x::StridedMatrix{Float64}) return (x, x) end In a global scope and/or REPL: x = eye(1); @show @allocated ha(x) @show @allocated ha(x) @show @allocated hs(x) @show @all…

---

## [Is there any reason to set a metapackage to be precompiled?](https://discourse.julialang.org/t/is-there-any-reason-to-set-a-metapackage-to-be-precompiled/6744)

<div class="topic-metadata">

**Author:** [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Replies:** 2\
**Last updated:** [October 28, 2017, 4:28pm UTC](https://discourse.julialang.org/t/is-there-any-reason-to-set-a-metapackage-to-be-precompiled/6744 "2017-10-28T16:28:55Z")

</div>

I am curious if there’s any benefit to precompiling a metapackage. DifferentialEquations.jl reexports a ton of packages which all themselves precompile. But precompiling DifferentialEquations.jl seems to precompile all …

---

## [Performance issues with Boolean dot operators](https://discourse.julialang.org/t/performance-issues-with-boolean-dot-operators/6665)

<div class="topic-metadata">

**Author:** [@rcnlee](https://discourse.julialang.org/u/rcnlee)\
**Replies:** 5\
**Last updated:** [October 24, 2017, 10:19pm UTC](https://discourse.julialang.org/t/performance-issues-with-boolean-dot-operators/6665 "2017-10-24T22:19:34Z")

</div>

I’m seeing poor performance in Boolean dot operators, such as .& and .!. Please see below. Any ideas why? Thanks! julia\> using BenchmarkTools julia\> x, y = rand(Bool,100), rand(Bool,100) (Bool\[false, true, true, tru…

---

## [Why is this code so slow in julia compared to a numpy implementation?](https://discourse.julialang.org/t/why-is-this-code-so-slow-in-julia-compared-to-a-numpy-implementation/6660)

<div class="topic-metadata">

**Author:** [@ksmet1977](https://discourse.julialang.org/u/ksmet1977)\
**Replies:** 9\
**Last updated:** [October 24, 2017, 5:11pm UTC](https://discourse.julialang.org/t/why-is-this-code-so-slow-in-julia-compared-to-a-numpy-implementation/6660 "2017-10-24T17:11:36Z")

</div>

I have implemented some mathematical models in Python that require basic operation like scalar multiplication, summing, raising power, etc. of arrays (upto 3d) and scalars. I find that my Julia code is substantially slo…

---

## [Parallel code seems slow](https://discourse.julialang.org/t/parallel-code-seems-slow/6588)

<div class="topic-metadata">

**Author:** [@maxtremblay](https://discourse.julialang.org/u/maxtremblay)\
**Replies:** 3\
**Last updated:** [October 20, 2017, 8:35pm UTC](https://discourse.julialang.org/t/parallel-code-seems-slow/6588 "2017-10-20T20:35:09Z")

</div>

Hello, I have a code that I want to run multiple times with different random inputs to compute an average overall all iterations. To get more familiar with parallel programming in Julia, I tried to play around with a s…

---

## [Closure which discards the return is slower?](https://discourse.julialang.org/t/closure-which-discards-the-return-is-slower/6583)

<div class="topic-metadata">

**Author:** [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Replies:** 7\
**Last updated:** [October 20, 2017, 7:34pm UTC](https://discourse.julialang.org/t/closure-which-discards-the-return-is-slower/6583 "2017-10-20T19:34:05Z")

</div>

using FunctionWrappers struct CallbackF64 f::FunctionWrappers.FunctionWrapper{Void,Tuple{Array{Float64}}} end (cb::CallbackF64)(v) = cb.f(v) f!(u) = (u.=u.^2) f = CallbackF64(f!) u = Float64\[1,2,3\] f(u) # Errors g!(u)…

---

## [How to optimize such a program](https://discourse.julialang.org/t/how-to-optimize-such-a-program/6527)

<div class="topic-metadata">

**Author:** [@Chong\_Wang](https://discourse.julialang.org/u/Chong_Wang)\
**Replies:** 8\
**Last updated:** [October 20, 2017, 3:39pm UTC](https://discourse.julialang.org/t/how-to-optimize-such-a-program/6527 "2017-10-20T15:39:23Z")

</div>

struct TightBindingModel norbits::Int64 lat::Matrix{Float64} end function makesupercell(t::TightBindingModel, scrdlat::Matrix{Int64}) ucs = Vector{Vector{Int64}}() scrdlatinv = inv(scrdlat) for k in …

---

## [Make this code fast (median pooling)](https://discourse.julialang.org/t/make-this-code-fast-median-pooling/6405)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 5\
**Last updated:** [October 18, 2017, 10:07am UTC](https://discourse.julialang.org/t/make-this-code-fast-median-pooling/6405 "2017-10-18T10:07:56Z")

</div>

I have an image say of size (1000,1000) and I want to reduce it to size (200,200) by tiling it with (5,5) batches and replacing each batch by its median. (The purpose of median is to remove some salt pepper like artifact…

---

## [How to speed up calculating large array?](https://discourse.julialang.org/t/how-to-speed-up-calculating-large-array/6466)

<div class="topic-metadata">

**Author:** [@Wonki\_Lee](https://discourse.julialang.org/u/Wonki_Lee)\
**Replies:** 11\
**Last updated:** [October 16, 2017, 4:16pm UTC](https://discourse.julialang.org/t/how-to-speed-up-calculating-large-array/6466 "2017-10-16T16:16:08Z")

</div>

Hi, I’m wondering if I could decrease the computation time for calculating large size array. Because I was new to Julia, I almost copied the format of ‘advection\_shared!(q,u)’ in https://docs.julialang.org/en/latest/man…

---

## [Surprising performance characteristic: What is happening here?](https://discourse.julialang.org/t/surprising-performance-characteristic-what-is-happening-here/6420)

<div class="topic-metadata">

**Author:** [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Replies:** 4\
**Last updated:** [October 14, 2017, 9:56am UTC](https://discourse.julialang.org/t/surprising-performance-characteristic-what-is-happening-here/6420 "2017-10-14T09:56:03Z")

</div>

I ran into some performance discrepancies, which I do not completely understand. Maybe someone of you has an idea? I want to compute the product of a vector of elements of length 2^k (for simplicity). But instead of co…

---

## [Performance: mutable vs immutable structs](https://discourse.julialang.org/t/performance-mutable-vs-immutable-structs/6221)

<div class="topic-metadata">

**Author:** [@tryingtosolve](https://discourse.julialang.org/u/tryingtosolve)\
**Replies:** 4\
**Last updated:** [October 4, 2017, 9:10am UTC](https://discourse.julialang.org/t/performance-mutable-vs-immutable-structs/6221 "2017-10-04T09:10:36Z")

</div>

In my code, I need to create a struct to hold two vectors. In terms of speed and memory allocations, would it make a difference if I make it mutable instead of immutable, assuming that there’s no need to make to mutable? …

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