# Performance

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

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

**Page:** 130

---

## [Optimizing Multidimensional Discrete Trapezoidal Integral](https://discourse.julialang.org/t/optimizing-multidimensional-discrete-trapezoidal-integral/24598)

<div class="topic-metadata">

**Author:** [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)\
**Replies:** 12\
**Last updated:** [May 28, 2019, 9:45am UTC](https://discourse.julialang.org/t/optimizing-multidimensional-discrete-trapezoidal-integral/24598 "2019-05-28T09:45:00Z")

</div>

Update: Turned the fastest code in this thread in a small self contained package, in case someone needs it. Original Content of the post using BenchmarkTools @fastmath function trapz(x::T1, y::T2) where {fT,T1\<:Abstra…

---

## [How to speed up this simple code? Multithreading, simd, inbounds](https://discourse.julialang.org/t/how-to-speed-up-this-simple-code-multithreading-simd-inbounds/19681)

<div class="topic-metadata">

**Author:** [@Juan](https://discourse.julialang.org/u/Juan)\
**Replies:** 39\
**Last updated:** [January 29, 2019, 8:22pm UTC](https://discourse.julialang.org/t/how-to-speed-up-this-simple-code-multithreading-simd-inbounds/19681 "2019-01-29T20:22:20Z")

</div>

I’m starting to use Julia and comparing its speed to R. For this simple example their speeds are almost the same. How would you make it faster? function f2(N) S = 0 Threads.@threads for i in 1:N se = 1:i …

---

## [How much of a difference does avoiding allocations make?](https://discourse.julialang.org/t/how-much-of-a-difference-does-avoiding-allocations-make/24585)

<div class="topic-metadata">

**Author:** [@jules](https://discourse.julialang.org/u/jules)\
**Replies:** 15\
**Last updated:** [May 25, 2019, 1:44pm UTC](https://discourse.julialang.org/t/how-much-of-a-difference-does-avoiding-allocations-make/24585 "2019-05-25T13:44:16Z")

</div>

I was wondering how much use it is to try and prohibit allocations in different scenarios. One case that came to mind was taking the median of many equally sized arrays. I was doing this with an array of arrays: medians…

---

## [Array of functions - is there a way to avoid allocations performance penalty?](https://discourse.julialang.org/t/array-of-functions-is-there-a-way-to-avoid-allocations-performance-penalty/24471)

<div class="topic-metadata">

**Author:** [@donboyd5](https://discourse.julialang.org/u/donboyd5)\
**Replies:** 23\
**Last updated:** [May 23, 2019, 11:04am UTC](https://discourse.julialang.org/t/array-of-functions-is-there-a-way-to-avoid-allocations-performance-penalty/24471 "2019-05-23T11:04:26Z")

</div>

Edited version of my initial post based upon the response from @Raf. After I wrote this post (1) I got advice on how to write a better post. I have taken that advice below, and (2) I actually found the answer to my post…

---

## [Julia with respect to reliability, sustainability, critical application, dynamic/static typing, big data, HPC?](https://discourse.julialang.org/t/julia-with-respect-to-reliability-sustainability-critical-application-dynamic-static-typing-big-data-hpc/23135)

<div class="topic-metadata">

**Author:** [@steph\_de\_paris](https://discourse.julialang.org/u/steph_de_paris)\
**Replies:** 51\
**Last updated:** [May 22, 2019, 10:01pm UTC](https://discourse.julialang.org/t/julia-with-respect-to-reliability-sustainability-critical-application-dynamic-static-typing-big-data-hpc/23135 "2019-05-22T22:01:21Z")

</div>

Hello, I am testing Julia langage for critical applications for which our codes do not have the right to bug. So, together with my practical tests, I would like to find some general informations coming from universities…

---

## [Skipping over loop index](https://discourse.julialang.org/t/skipping-over-loop-index/24489)

<div class="topic-metadata">

**Author:** [@tyleransom](https://discourse.julialang.org/u/tyleransom)\
**Replies:** 2\
**Last updated:** [May 22, 2019, 7:31pm UTC](https://discourse.julialang.org/t/skipping-over-loop-index/24489 "2019-05-22T19:31:03Z")

</div>

Consider the following code, where I want to take a difference across columns of a matrix. for j=1:(J-1) Z\[:,j\] .= X\[:,j\].-X\[:,J\] end However, I want to allow the last term to be a column potentially di…

---

## [Problem about option-readtimeout@HTTP](https://discourse.julialang.org/t/problem-about-option-readtimeout-http/24458)

<div class="topic-metadata">

**Author:** [@remedisbetty](https://discourse.julialang.org/u/remedisbetty)\
**Replies:** 0\
**Last updated:** [May 22, 2019, 3:36am UTC](https://discourse.julialang.org/t/problem-about-option-readtimeout-http/24458 "2019-05-22T03:36:14Z")

</div>

When I used the HTTP.request to send job to clients, I get a response of timeout and connection closed after 60s. While, it seems that the option readtimeout doesn’t work. for details, please refer to this URL https:…

---

## [Networks' Simulation](https://discourse.julialang.org/t/networks-simulation/24239)

<div class="topic-metadata">

**Author:** [@ennvvy](https://discourse.julialang.org/u/ennvvy)\
**Replies:** 7\
**Last updated:** [May 21, 2019, 5:18pm UTC](https://discourse.julialang.org/t/networks-simulation/24239 "2019-05-21T17:18:41Z")

</div>

I have been using Julia to simulate calculations involving directed networks. Monte Carlo simulations(100 iterations) with a network with 100 nodes used to take 10mins. But the code doesn’t scale well, for a directed net…

---

## [Closures: Is this docs sentence still relevant?](https://discourse.julialang.org/t/closures-is-this-docs-sentence-still-relevant/24432)

<div class="topic-metadata">

**Author:** [@francesco.alemanno](https://discourse.julialang.org/u/francesco.alemanno)\
**Replies:** 1\
**Last updated:** [May 21, 2019, 2:01pm UTC](https://discourse.julialang.org/t/closures-is-this-docs-sentence-still-relevant/24432 "2019-05-21T14:01:32Z")

</div>

Last sentence in the page performance tips “In the mean time, some user-contributed packages like FastClosures automate the insertion of let statements as in abmult3 .” Perf. Tips \[latest docs\] i used closures heavily…

---

## [Thread-local let bindings?](https://discourse.julialang.org/t/thread-local-let-bindings/24290)

<div class="topic-metadata">

**Author:** [@robsmith11](https://discourse.julialang.org/u/robsmith11)\
**Replies:** 1\
**Last updated:** [May 16, 2019, 8:07pm UTC](https://discourse.julialang.org/t/thread-local-let-bindings/24290 "2019-05-16T20:07:06Z")

</div>

I’m running into performance problems when my multithreaded code allocates heavily, so I’m trying to use let bindings to avoid reallocating large arrays, but I don’t see any way to make the bindings thread-local. For ex…

---

## [Broadcast of .== slow performance, allocations](https://discourse.julialang.org/t/broadcast-of-slow-performance-allocations/24259)

<div class="topic-metadata">

**Author:** [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Replies:** 5\
**Last updated:** [May 16, 2019, 9:57am UTC](https://discourse.julialang.org/t/broadcast-of-slow-performance-allocations/24259 "2019-05-16T09:57:53Z")

</div>

Why is .== so slow compared to broadcast in this example? julia\> test = \[1\] 1-element Array{Int64,1}: 1 julia\> @btime test .== 1 3.304 μs (13 allocations: 4.72 KiB) 1-element BitArray{1}: true julia\> @btime broadc…

---

## [Very slow array creation (and Benchmark iterate error)](https://discourse.julialang.org/t/very-slow-array-creation-and-benchmark-iterate-error/24020)

<div class="topic-metadata">

**Author:** [@HelgavonLichtenstein](https://discourse.julialang.org/u/HelgavonLichtenstein)\
**Replies:** 6\
**Last updated:** [May 15, 2019, 3:03pm UTC](https://discourse.julialang.org/t/very-slow-array-creation-and-benchmark-iterate-error/24020 "2019-05-15T15:03:28Z")

</div>

I am a beginner Julia user and am having a hard time developing a model because it takes a very long time to initialize certain arrays. I tried using BenchmarkTools.jl to get an accurate time but it generated an iterate …

---

## [Advice for building sparsematrix](https://discourse.julialang.org/t/advice-for-building-sparsematrix/18178)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 10\
**Last updated:** [May 14, 2019, 5:25pm UTC](https://discourse.julialang.org/t/advice-for-building-sparsematrix/18178 "2019-05-14T17:25:03Z")

</div>

Hi, I feel that my problem must be shared by some of you. I need to build the sparse matrix associated to a 2d Finite Element method. Following the advice of Viral, I built 3 lists I,J,values containing the indices of …

---

## [Array Type and Values-as-Parameters Performance penalty?](https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092)

<div class="topic-metadata">

**Author:** [@ianfiske](https://discourse.julialang.org/u/ianfiske)\
**Replies:** 2\
**Last updated:** [May 13, 2019, 12:39pm UTC](https://discourse.julialang.org/t/array-type-and-values-as-parameters-performance-penalty/24092 "2019-05-13T12:39:52Z")

</div>

The user manual at Performance Tips · The Julia Language suggests that we avoid types with values as parameters. However, doesn’t the base Array{T, N} have a value-parameter N? How can Base get away with this but have …

---

## [Interpreting @trace dynamic dispatch warning on apply\_type](https://discourse.julialang.org/t/interpreting-trace-dynamic-dispatch-warning-on-apply-type/24138)

<div class="topic-metadata">

**Author:** [@venuur](https://discourse.julialang.org/u/venuur)\
**Replies:** 2\
**Last updated:** [May 12, 2019, 9:16pm UTC](https://discourse.julialang.org/t/interpreting-trace-dynamic-dispatch-warning-on-apply-type/24138 "2019-05-12T21:16:25Z")

</div>

New to Julia, and I am trying to build good habits for writing functions. To that end I am applying the Traceur.trace macro to some of my functions and seeing what happens. Here’s an example I don’t understand. When I ru…

---

## [What can cause significantly different performance for pisum microbenchmark on different workstations](https://discourse.julialang.org/t/what-can-cause-significantly-different-performance-for-pisum-microbenchmark-on-different-workstations/23256)

<div class="topic-metadata">

**Author:** [@adityam](https://discourse.julialang.org/u/adityam)\
**Replies:** 11\
**Last updated:** [May 12, 2019, 1:37am UTC](https://discourse.julialang.org/t/what-can-cause-significantly-different-performance-for-pisum-microbenchmark-on-different-workstations/23256 "2019-05-12T01:37:57Z")

</div>

I am trying to understand what factors impact the performance of Julia code on different hardware. I have two workstations: WS1 is a three old old compute server and WS2 is a two year old desktop, both of which have comp…

---

## ["Composing" functions](https://discourse.julialang.org/t/composing-functions/24096)

<div class="topic-metadata">

**Author:** [@asprionj](https://discourse.julialang.org/u/asprionj)\
**Replies:** 1\
**Last updated:** [May 11, 2019, 12:06am UTC](https://discourse.julialang.org/t/composing-functions/24096 "2019-05-11T00:06:32Z")

</div>

Hi, I’m in a situation where I have to assemble an overall function from many other functions. I’m using code generation to create the overall function, so it does not really matter whether the implementation is “nice an…

---

## [Sequential peakflops](https://discourse.julialang.org/t/sequential-peakflops/24066)

<div class="topic-metadata">

**Author:** [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Replies:** 2\
**Last updated:** [May 10, 2019, 2:36pm UTC](https://discourse.julialang.org/t/sequential-peakflops/24066 "2019-05-10T14:36:07Z")

</div>

Hi Julians, When I use peakflops(8000;parallel=false) I obtain 1.266034664857239e11 which corresponds to (IMHO) the multicore peak perf of my PC. In addition I see top reaching 800%. The parallel flag seems to be …

---

## [How to avoid allocation when modifying a structure in a function](https://discourse.julialang.org/t/how-to-avoid-allocation-when-modifying-a-structure-in-a-function/24062)

<div class="topic-metadata">

**Author:** [@flibe](https://discourse.julialang.org/u/flibe)\
**Replies:** 2\
**Last updated:** [May 10, 2019, 9:03am UTC](https://discourse.julialang.org/t/how-to-avoid-allocation-when-modifying-a-structure-in-a-function/24062 "2019-05-10T09:03:51Z")

</div>

Dear All I have a function which I need to make as efficient as possible. The function takes many many inputs, and I have organised them into a structure in order to make the code more manageble and clean. I have noti…

---

## [What is the real @time for an MPI program?](https://discourse.julialang.org/t/what-is-the-real-time-for-an-mpi-program/23458)

<div class="topic-metadata">

**Author:** [@Carol](https://discourse.julialang.org/u/Carol)\
**Replies:** 5\
**Last updated:** [May 10, 2019, 1:07am UTC](https://discourse.julialang.org/t/what-is-the-real-time-for-an-mpi-program/23458 "2019-05-10T01:07:44Z")

</div>

Hi, I have a question on timing an MPI code, because I want to test its performance. For example, if I split my code into 10 parallel jobs using MPI, then the @time will return 10 timing records. BTW, I also try to us…

---

## [Julia's in.() seems slow compared to R's %in%](https://discourse.julialang.org/t/julias-in-seems-slow-compared-to-rs-in/23900)

<div class="topic-metadata">

**Author:** [@alasaadstat](https://discourse.julialang.org/u/alasaadstat)\
**Replies:** 40\
**Last updated:** [May 9, 2019, 8:05pm UTC](https://discourse.julialang.org/t/julias-in-seems-slow-compared-to-rs-in/23900 "2019-05-09T20:05:36Z")

</div>

Hi everyone, I want to compare if elements of vector x are in elements of vector y. In R, I can do this as follows: \> x \<- c("a", "b", "c") \> y \<- c("b", "a") \> x %in% y \[1\] TRUE TRUE FALSE In Julia, I can do this a…

---

## [Fast Replotting](https://discourse.julialang.org/t/fast-replotting/24042)

<div class="topic-metadata">

**Author:** [@bjack205](https://discourse.julialang.org/u/bjack205)\
**Replies:** 2\
**Last updated:** [May 9, 2019, 7:19pm UTC](https://discourse.julialang.org/t/fast-replotting/24042 "2019-05-09T19:19:35Z")

</div>

I can’t figure out the best way to continuously update a plot. I’ve dug around but haven’t found a good example of how to do this, yet. My use case is running simulations of dynamical systems, and I’d like to see how th…

---

## [Matrix Multiplication A\*B\*A'](https://discourse.julialang.org/t/matrix-multiplication-a-b-a/24019)

<div class="topic-metadata">

**Author:** [@Marco-Congedo](https://discourse.julialang.org/u/Marco-Congedo)\
**Replies:** 5\
**Last updated:** [May 9, 2019, 3:39pm UTC](https://discourse.julialang.org/t/matrix-multiplication-a-b-a/24019 "2019-05-09T15:39:00Z")

</div>

What are the efficient options to perform matrix multiplications of the form A\*B\*A and A\*B\*A' ? I am particularly intereted in the case when A and B are Symmetric or Hermitian and when these multiplications are performed…

---

## [Why does exporting a single Float64 from a function take as long as 2,000,000 addition steps](https://discourse.julialang.org/t/why-does-exporting-a-single-float64-from-a-function-take-as-long-as-2-000-000-addition-steps/24008)

<div class="topic-metadata">

**Author:** [@damonturney](https://discourse.julialang.org/u/damonturney)\
**Replies:** 21\
**Last updated:** [May 9, 2019, 9:04am UTC](https://discourse.julialang.org/t/why-does-exporting-a-single-float64-from-a-function-take-as-long-as-2-000-000-addition-steps/24008 "2019-05-09T09:04:15Z")

</div>

Hi Forum, Can someone enlighten me as to why a single Float64 export from inside a function takes as much computation time as 2,000,000 additions? See code below from Julia 1.1. module test struct teststruct …

---

## [Efficient traversal of tree defined as nested structs](https://discourse.julialang.org/t/efficient-traversal-of-tree-defined-as-nested-structs/23772)

<div class="topic-metadata">

**Author:** [@jonalm](https://discourse.julialang.org/u/jonalm)\
**Replies:** 2\
**Last updated:** [May 8, 2019, 12:42pm UTC](https://discourse.julialang.org/t/efficient-traversal-of-tree-defined-as-nested-structs/23772 "2019-05-08T12:42:06Z")

</div>

Edit: this question has been reformulated here: How to unroll tree traversal efficiently? Dear Community, I would greatly appreciate some pointers to how I could speed up my code. Some background: I tried to write …

---

## [Working on a pattern for interface-based dispatch that uses code-generation. Is this efficient?](https://discourse.julialang.org/t/working-on-a-pattern-for-interface-based-dispatch-that-uses-code-generation-is-this-efficient/23904)

<div class="topic-metadata">

**Author:** [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)\
**Replies:** 7\
**Last updated:** [May 6, 2019, 12:22pm UTC](https://discourse.julialang.org/t/working-on-a-pattern-for-interface-based-dispatch-that-uses-code-generation-is-this-efficient/23904 "2019-05-06T12:22:33Z")

</div>

I’m not a super fan of inheritance-based polymorphism. I tend to like interface-based polymorphism like Go’s interfaces and Haskell’s type classes, et al. I realize retrofitting these features in Julia is thought to be …

---

## [Julia function performance behaving strange when combining broadcasting, a NamedTuple of Parameters, and a function as argument](https://discourse.julialang.org/t/julia-function-performance-behaving-strange-when-combining-broadcasting-a-namedtuple-of-parameters-and-a-function-as-argument/23888)

<div class="topic-metadata">

**Author:** [@OvidiusCicero](https://discourse.julialang.org/u/OvidiusCicero)\
**Replies:** 2\
**Last updated:** [May 6, 2019, 7:12am UTC](https://discourse.julialang.org/t/julia-function-performance-behaving-strange-when-combining-broadcasting-a-namedtuple-of-parameters-and-a-function-as-argument/23888 "2019-05-06T07:12:25Z")

</div>

I have the following simplified example taken from real code that calculates a function over a difference for a vector of inputs and a function input params = (a=2,b=3) # calc(p::NamedTuple, t) = p.a\*t^2+p.b\*t^3 # Examp…

---

## [Effective simulation of putting n-1 balls in n boxes uniformly at random](https://discourse.julialang.org/t/effective-simulation-of-putting-n-1-balls-in-n-boxes-uniformly-at-random/23774)

<div class="topic-metadata">

**Author:** [@Xing\_Shi\_Cai](https://discourse.julialang.org/u/Xing_Shi_Cai)\
**Replies:** 12\
**Last updated:** [May 4, 2019, 1:07am UTC](https://discourse.julialang.org/t/effective-simulation-of-putting-n-1-balls-in-n-boxes-uniformly-at-random/23774 "2019-05-04T01:07:14Z")

</div>

I am trying to learn Julia so I wrote a bit code to test its performance. In the following code snippet I created a function balls\_in\_box to simulate putting n-1 balls in n boxes uniformly at random. One my machine, on…

---

## [Is Julia able to optimize functions that can either return one specific type or \`nothing\`?](https://discourse.julialang.org/t/is-julia-able-to-optimize-functions-that-can-either-return-one-specific-type-or-nothing/23813)

<div class="topic-metadata">

**Author:** [@ninjaaron](https://discourse.julialang.org/u/ninjaaron)\
**Replies:** 2\
**Last updated:** [May 3, 2019, 3:10pm UTC](https://discourse.julialang.org/t/is-julia-able-to-optimize-functions-that-can-either-return-one-specific-type-or-nothing/23813 "2019-05-03T15:10:02Z")

</div>

I know type stability of functions is a big factor in Julia performance, but I also Julia can also optimize Union{T,Nothing} where T in a lot of cases. Does this extend to functions without declared return types? I know …

---

## [Understanding the allocation behavior on arrays vs scalars](https://discourse.julialang.org/t/understanding-the-allocation-behavior-on-arrays-vs-scalars/23798)

<div class="topic-metadata">

**Author:** [@jeremiedb](https://discourse.julialang.org/u/jeremiedb)\
**Replies:** 5\
**Last updated:** [May 3, 2019, 3:22am UTC](https://discourse.julialang.org/t/understanding-the-allocation-behavior-on-arrays-vs-scalars/23798 "2019-05-03T03:22:46Z")

</div>

I am confused about the behavior of the allocation, as a significant gain in efficiency seems to be achieved by accumulating values into 2 scalars rather than a vector of 2 values. For the context, the function scans ov…

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

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