# Performance

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

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

**Page:** 65

---

## [How to count heap allocations easily?](https://discourse.julialang.org/t/how-to-count-heap-allocations-easily/68285)

<div class="topic-metadata">

**Author:** [@JeffFessler](https://discourse.julialang.org/u/JeffFessler)\
**Replies:** 4\
**Last updated:** [June 1, 2022, 10:31pm UTC](https://discourse.julialang.org/t/how-to-count-heap-allocations-easily/68285 "2022-06-01T22:31:52Z")

</div>

The manual recommends using @time and @allocated to examine memory use: https://docs.julialang.org/en/v1/manual/profile/#Memory-allocation-analysis It appears that both of those macros measure both stack and heap alloc…

---

## [Precompute some values of a function](https://discourse.julialang.org/t/precompute-some-values-of-a-function/82079)

<div class="topic-metadata">

**Author:** [@raphaelchinchilla](https://discourse.julialang.org/u/raphaelchinchilla)\
**Replies:** 7\
**Last updated:** [June 1, 2022, 8:46pm UTC](https://discourse.julialang.org/t/precompute-some-values-of-a-function/82079 "2022-06-01T20:46:20Z")

</div>

Consider the following MWE: d=rand(10^8); f(x,d) = x + sum(d) g(x) = f(x,d) If I run @benchmark f(1,d) and @benchmark g(1) (in the REPL), both take the same amount of time to run (which is what I kind of excepted). Is …

---

## [Understanding message passing with pmap](https://discourse.julialang.org/t/understanding-message-passing-with-pmap/82030)

<div class="topic-metadata">

**Author:** [@swishmas](https://discourse.julialang.org/u/swishmas)\
**Replies:** 3\
**Last updated:** [June 1, 2022, 6:38am UTC](https://discourse.julialang.org/t/understanding-message-passing-with-pmap/82030 "2022-06-01T06:38:53Z")

</div>

I was trying to understand the behaviour of pmap and how vectors are updated inside of a generic function call. I wanted to know if new variables were being constantly created in pmap and whether this was truly efficient…

---

## [Help with increasing performance in badly coded functions](https://discourse.julialang.org/t/help-with-increasing-performance-in-badly-coded-functions/81918)

<div class="topic-metadata">

**Author:** [@mauri5566](https://discourse.julialang.org/u/mauri5566)\
**Replies:** 5\
**Last updated:** [May 31, 2022, 6:27pm UTC](https://discourse.julialang.org/t/help-with-increasing-performance-in-badly-coded-functions/81918 "2022-05-31T18:27:18Z")

</div>

Hi guys, I need a little help with optimising the performance of a few functions. If you need a more detailed access to my project here’s a notebook (Largrids.jl/largrid.ipynb at main · adelloste/Largrids.jl · GitHub) th…

---

## [Anonymous function performance](https://discourse.julialang.org/t/anonymous-function-performance/81972)

<div class="topic-metadata">

**Author:** [@jerry\_ji](https://discourse.julialang.org/u/jerry_ji)\
**Replies:** 9\
**Last updated:** [May 31, 2022, 1:50pm UTC](https://discourse.julialang.org/t/anonymous-function-performance/81972 "2022-05-31T13:50:19Z")

</div>

Hi all, Following code shows performance penalty associate with anonymous function. However the @code\_llvm shows both code is the same. Am I benchmark it in a wrong way? using BenchmarkTools f1(x)=5+6x f2(x)=7+8x f…

---

## [Optionally multi threaded for loop](https://discourse.julialang.org/t/optionally-multi-threaded-for-loop/81902)

<div class="topic-metadata">

**Author:** [@this\_josh](https://discourse.julialang.org/u/this_josh)\
**Replies:** 9\
**Last updated:** [May 31, 2022, 10:14am UTC](https://discourse.julialang.org/t/optionally-multi-threaded-for-loop/81902 "2022-05-31T10:14:32Z")

</div>

I have a function which contains a loop which should normally be run multi threaded using Threads.@threads, but sometimes I want to run it single threaded. function foo(multi\_thread=true) mt = multi\_thread ? Threads…

---

## [Need help with example; Mixture Density Networks from Site](https://discourse.julialang.org/t/need-help-with-example-mixture-density-networks-from-site/81514)

<div class="topic-metadata">

**Author:** [@HerAdri](https://discourse.julialang.org/u/HerAdri)\
**Replies:** 25\
**Last updated:** [May 31, 2022, 8:41am UTC](https://discourse.julialang.org/t/need-help-with-example-mixture-density-networks-from-site/81514 "2022-05-31T08:41:00Z")

</div>

Tried to reproduce the example that you can see on the site: Mixture Density Networks But I don’t know how to update the following lines of code: # lowest-level? data = \[(y, x)\] for epoch = 1:n\_epochs # forw…

---

## [Package development tools - in environment but not dependency](https://discourse.julialang.org/t/package-development-tools-in-environment-but-not-dependency/81960)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 6\
**Last updated:** [May 31, 2022, 7:20am UTC](https://discourse.julialang.org/t/package-development-tools-in-environment-but-not-dependency/81960 "2022-05-31T07:20:44Z")

</div>

Hi, I am getting a package EspyInsideFunction.jl fairly formalized (testing, doc, registration…). But I still wonder about one thing: as part of development work I use Documenter.jl, Test.jl and ProfileView.jl, so they…

---

## [Contents of the function run well when timed alone, but not when they are in a loop inside the function](https://discourse.julialang.org/t/contents-of-the-function-run-well-when-timed-alone-but-not-when-they-are-in-a-loop-inside-the-function/76886)

<div class="topic-metadata">

**Author:** [@ayushinav](https://discourse.julialang.org/u/ayushinav)\
**Replies:** 8\
**Last updated:** [May 31, 2022, 5:02am UTC](https://discourse.julialang.org/t/contents-of-the-function-run-well-when-timed-alone-but-not-when-they-are-in-a-loop-inside-the-function/76886 "2022-05-31T05:02:21Z")

</div>

Hello all, I am new to Julia and have been making progress with implementing its performance utilities. Generally, I am able to get some results or an understanding of how things are going, but not in this case. The fol…

---

## [Extra allocations/time when a function is returned from another function than defined directly](https://discourse.julialang.org/t/extra-allocations-time-when-a-function-is-returned-from-another-function-than-defined-directly/81933)

<div class="topic-metadata">

**Author:** [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Replies:** 6\
**Last updated:** [May 30, 2022, 11:18pm UTC](https://discourse.julialang.org/t/extra-allocations-time-when-a-function-is-returned-from-another-function-than-defined-directly/81933 "2022-05-30T23:18:30Z")

</div>

The code below compares the results when computing a function when it is returned from another to when it is defined directly. Why is the returned version so much slower, and require any allocations at all? I can see fro…

---

## [AdaptiveMCMC](https://discourse.julialang.org/t/adaptivemcmc/81399)

<div class="topic-metadata">

**Author:** [@marouane1994](https://discourse.julialang.org/u/marouane1994)\
**Replies:** 9\
**Last updated:** [May 30, 2022, 5:20pm UTC](https://discourse.julialang.org/t/adaptivemcmc/81399 "2022-05-30T17:20:17Z")

</div>

I wrote a Metropolis-Hastings code manually for a problem that samples arrays from a custom distribution that can be found here https://github.com/marouanehanhasse/QComm/blob/main/distributions.jl, before i was using Kla…

---

## [Mv() in Windows](https://discourse.julialang.org/t/mv-in-windows/81904)

<div class="topic-metadata">

**Author:** [@Philippe\_Maincon1](https://discourse.julialang.org/u/Philippe_Maincon1)\
**Replies:** 6\
**Last updated:** [May 30, 2022, 9:22am UTC](https://discourse.julialang.org/t/mv-in-windows/81904 "2022-05-30T09:22:19Z")

</div>

I have two directories A and B(preexisting, with files in them) and I want to move, or copy the files inside A to B - without loosing previous content of B. So I type mv(A\*"\\\\\*",B) but get 'B' exists. \`force=true\` i…

---

## [Naive lookup table with lots of allocations](https://discourse.julialang.org/t/naive-lookup-table-with-lots-of-allocations/65457)

<div class="topic-metadata">

**Author:** [@daviddoij](https://discourse.julialang.org/u/daviddoij)\
**Replies:** 11\
**Last updated:** [May 30, 2022, 3:30am UTC](https://discourse.julialang.org/t/naive-lookup-table-with-lots-of-allocations/65457 "2022-05-30T03:30:48Z")

</div>

Hi there, going through project euler problems, I’ve implemented a working solution for problem 17: function num2letters(num) nums = Dict( 0 =\> "", 1 =\> "one", 2 =\> "two", 3 =\> "three", 4 =\> "four", 5 =\> "f…

---

## [Using serial ports](https://discourse.julialang.org/t/using-serial-ports/81604)

<div class="topic-metadata">

**Author:** [@nhardy](https://discourse.julialang.org/u/nhardy)\
**Replies:** 8\
**Last updated:** [May 28, 2022, 7:04pm UTC](https://discourse.julialang.org/t/using-serial-ports/81604 "2022-05-28T19:04:12Z")

</div>

So, I am trying to stream data from a device over a serial port (RS232 via USB) in realtime. I saw two packages to talk to serial ports, SerialPorts (a wrapper on the Python SerialPorts package) and LibSerialPorts (a wra…

---

## [Why is dot plus faster?](https://discourse.julialang.org/t/why-is-dot-plus-faster/81830)

<div class="topic-metadata">

**Author:** [@thisismygitrepo](https://discourse.julialang.org/u/thisismygitrepo)\
**Replies:** 6\
**Last updated:** [May 28, 2022, 12:57pm UTC](https://discourse.julialang.org/t/why-is-dot-plus-faster/81830 "2022-05-28T12:57:52Z")

</div>

I’m experimenting with differnt expression and I can’t explain why the dot + is faster than just + in the simple case of matrix addition. using BenchmarkTools A = rand(100, 100) B = rand(100, 100) function no\_dot(A,…

---

## [Is it possible to see performant string processing without sacrificing ease of use in Julia one day?](https://discourse.julialang.org/t/is-it-possible-to-see-performant-string-processing-without-sacrificing-ease-of-use-in-julia-one-day/81698)

<div class="topic-metadata">

**Author:** [@ReneganRonin](https://discourse.julialang.org/u/ReneganRonin)\
**Replies:** 7\
**Last updated:** [May 28, 2022, 2:46am UTC](https://discourse.julialang.org/t/is-it-possible-to-see-performant-string-processing-without-sacrificing-ease-of-use-in-julia-one-day/81698 "2022-05-28T02:46:07Z")

</div>

I have heard a lot that string performance in Julia is bad. So is it possible to see performant string processing without sacrificing ease of use in Julia one day?

---

## [Problems with Optimising Function](https://discourse.julialang.org/t/problems-with-optimising-function/81601)

<div class="topic-metadata">

**Author:** [@mauri5566](https://discourse.julialang.org/u/mauri5566)\
**Replies:** 2\
**Last updated:** [May 27, 2022, 6:05pm UTC](https://discourse.julialang.org/t/problems-with-optimising-function/81601 "2022-05-27T18:05:15Z")

</div>

I’m having a tough time optimising and parallelising this function that executes a simplex extrusion (solid modeling). Anything to make it faster would be great, even a couple macros. function extrudeSimplicial(model::L…

---

## [Arithmetic broadcasting in Julia 5x slower than MATLAB](https://discourse.julialang.org/t/arithmetic-broadcasting-in-julia-5x-slower-than-matlab/81628)

<div class="topic-metadata">

**Author:** [@elenev](https://discourse.julialang.org/u/elenev)\
**Replies:** 17\
**Last updated:** [May 26, 2022, 12:46am UTC](https://discourse.julialang.org/t/arithmetic-broadcasting-in-julia-5x-slower-than-matlab/81628 "2022-05-26T00:46:42Z")

</div>

I was surprised to find a fairly simple broadcasting operation on somewhat large arrays be considerably slower in Julia relative to MATLAB. Is there some unattainable level of optimization that folks at MathWorks have fi…

---

## [Type instability with tuples of functions and parameters](https://discourse.julialang.org/t/type-instability-with-tuples-of-functions-and-parameters/81588)

<div class="topic-metadata">

**Author:** [@DanielVandH](https://discourse.julialang.org/u/DanielVandH)\
**Replies:** 13\
**Last updated:** [May 25, 2022, 6:30am UTC](https://discourse.julialang.org/t/type-instability-with-tuples-of-functions-and-parameters/81588 "2022-05-25T06:30:19Z")

</div>

My general application of interest requires a vector of functions of the form f(x, y, p), for some known parameters p. I put the functions in a Tuple so that their types are known, and define for example the following st…

---

## [Yet another TCO thread](https://discourse.julialang.org/t/yet-another-tco-thread/81146)

<div class="topic-metadata">

**Author:** [@Seif\_Shebl](https://discourse.julialang.org/u/Seif_Shebl)\
**Replies:** 5\
**Last updated:** [May 25, 2022, 6:06am UTC](https://discourse.julialang.org/t/yet-another-tco-thread/81146 "2022-05-25T06:06:53Z")

</div>

Also, AFAIK, Julia doesn’t implement the tail-call optimization yet, which is crucial for the performance of recursive functions.

---

## [How to efficiently handle parallelism on a DistributedArray](https://discourse.julialang.org/t/how-to-efficiently-handle-parallelism-on-a-distributedarray/81098)

<div class="topic-metadata">

**Author:** [@ultrapoci](https://discourse.julialang.org/u/ultrapoci)\
**Replies:** 8\
**Last updated:** [May 24, 2022, 10:03am UTC](https://discourse.julialang.org/t/how-to-efficiently-handle-parallelism-on-a-distributedarray/81098 "2022-05-24T10:03:38Z")

</div>

I’m working with a DArray from DistributedArrays.jl. I want each process to work on its own part of the array independently, and access the rest of the array only when it needs a nearest neighbor which doesn’t reside in …

---

## [Passing struct with Union type to other function](https://discourse.julialang.org/t/passing-struct-with-union-type-to-other-function/81482)

<div class="topic-metadata">

**Author:** [@yhchang96](https://discourse.julialang.org/u/yhchang96)\
**Replies:** 6\
**Last updated:** [May 23, 2022, 8:01pm UTC](https://discourse.julialang.org/t/passing-struct-with-union-type-to-other-function/81482 "2022-05-23T20:01:45Z")

</div>

I’m pretty new to Julia so I might have missed something pretty elementary. I have defined the following struct which contains some parameters with default values. @with\_kw struct Par1 D::Union{Float64, VecOrMat{Fl…

---

## [If mutiple dispatch is done at compile time, wouldn't that make things faster?](https://discourse.julialang.org/t/if-mutiple-dispatch-is-done-at-compile-time-wouldnt-that-make-things-faster/81496)

<div class="topic-metadata">

**Author:** [@thisismygitrepo](https://discourse.julialang.org/u/thisismygitrepo)\
**Replies:** 3\
**Last updated:** [May 23, 2022, 1:44pm UTC](https://discourse.julialang.org/t/if-mutiple-dispatch-is-done-at-compile-time-wouldnt-that-make-things-faster/81496 "2022-05-23T13:44:11Z")

</div>

I’m not an expert in any sense, but can we not get MOAR speed if we don’t have to check types at runtime? So, if my code is statically styled, would that make it faster?

---

## [Three million linear regressions](https://discourse.julialang.org/t/three-million-linear-regressions/81439)

<div class="topic-metadata">

**Author:** [@Baba\_Yara\_Fahiz](https://discourse.julialang.org/u/Baba_Yara_Fahiz)\
**Replies:** 4\
**Last updated:** [May 23, 2022, 12:52am UTC](https://discourse.julialang.org/t/three-million-linear-regressions/81439 "2022-05-23T00:52:39Z")

</div>

I am running three million regressions of the form below and I feel like I am leaving a lot of performance on the table. Can I get some tips to help speed things up? function test\_1(data\_0) EignVectors = rand(100, 12) …

---

## [Julia user's guide for the positive semidefinite program with variables in {-1,1}](https://discourse.julialang.org/t/julia-users-guide-for-the-positive-semidefinite-program-with-variables-in-1-1/81460)

<div class="topic-metadata">

**Author:** [@Huyen26n](https://discourse.julialang.org/u/Huyen26n)\
**Replies:** 1\
**Last updated:** [May 22, 2022, 5:31pm UTC](https://discourse.julialang.org/t/julia-users-guide-for-the-positive-semidefinite-program-with-variables-in-1-1/81460 "2022-05-22T17:31:25Z")

</div>

Dear all, I am using Julia for the first time to work on the positive semidefinite program. I’m trying to solve the PSD with variables in {-1,1}. I don’t understand how to write objective functions or variables, … I wis…

---

## [Type of composition of functions is not predictable](https://discourse.julialang.org/t/type-of-composition-of-functions-is-not-predictable/81446)

<div class="topic-metadata">

**Author:** [@Veenty](https://discourse.julialang.org/u/Veenty)\
**Replies:** 1\
**Last updated:** [May 22, 2022, 6:08am UTC](https://discourse.julialang.org/t/type-of-composition-of-functions-is-not-predictable/81446 "2022-05-22T06:08:15Z")

</div>

I’m trying to figure out why the type of this function is not predictable function η\_const(r, η\_) if r\>=1 return convert( typeof(r), 0.0) elseif r\<=0.8 return convert( typeof(r), 1.0) els…

---

## [Speed up a derivative calculation?](https://discourse.julialang.org/t/speed-up-a-derivative-calculation/80921)

<div class="topic-metadata">

**Author:** [@vshesh](https://discourse.julialang.org/u/vshesh)\
**Replies:** 10\
**Last updated:** [May 21, 2022, 2:04am UTC](https://discourse.julialang.org/t/speed-up-a-derivative-calculation/80921 "2022-05-21T02:04:41Z")

</div>

Hi, I am trying to write a function to compute the derivative of a cost function. The cost function is used to express how good a distance function is at separating labeled data into its respective classes. I’m trying …

---

## [Multi-threading to the “combine” function](https://discourse.julialang.org/t/multi-threading-to-the-combine-function/67783)

<div class="topic-metadata">

**Author:** [@bojusemo](https://discourse.julialang.org/u/bojusemo)\
**Replies:** 5\
**Last updated:** [May 20, 2022, 10:15am UTC](https://discourse.julialang.org/t/multi-threading-to-the-combine-function/67783 "2022-05-20T10:15:43Z")

</div>

Hello folks, Could anybody guide me, please? Can multi-threading be designated to the “combine” function in the example below? Thank you in advance Boris julia\> begin using DataFrames, Chain d…

---

## [Need help with incomprehensible typeinference](https://discourse.julialang.org/t/need-help-with-incomprehensible-typeinference/81056)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 9\
**Last updated:** [May 20, 2022, 9:44am UTC](https://discourse.julialang.org/t/need-help-with-incomprehensible-typeinference/81056 "2022-05-20T09:44:01Z")

</div>

Hi there, I am the author of ExtensibleEffects.jl. This is an advanced functional package, hence please bear with me if the following example looks totally alien and not understandable why you ever would like to do some…

---

## [Using Julia on a cluster](https://discourse.julialang.org/t/using-julia-on-a-cluster/80755)

<div class="topic-metadata">

**Author:** [@Marius\_123](https://discourse.julialang.org/u/Marius_123)\
**Replies:** 2\
**Last updated:** [May 20, 2022, 9:37am UTC](https://discourse.julialang.org/t/using-julia-on-a-cluster/80755 "2022-05-20T09:37:46Z")

</div>

Hello, i am new to parallel computing and wanted to parallelize a for loop. This for loop is embarassingly parallel. In each iteration of the for loop it calls sciml\_train with a initial guess and computes a parameter e…

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

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