# \#unrolling

**URL:** https://discourse.julialang.org/tag/unrolling/820.md

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

---

## [Unrolling loops over tuples - why so hard?](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 14\
**Last updated:** [September 10, 2023, 10:58pm UTC](https://discourse.julialang.org/t/unrolling-loops-over-tuples-why-so-hard/103428 "2023-09-10T22:58:11Z")

</div>

Unrolling loops over tuple elements can bring easy performance gains. Here’s a trivial example of a 250x speed-up, just by adding an @unroll macro to the code: import Unroll.@unroll using BenchmarkTools function nounro…

---

## [Optimisations for loops of known size at compile time](https://discourse.julialang.org/t/optimisations-for-loops-of-known-size-at-compile-time/78474)

<div class="topic-metadata">

**Author:** [@Luapulu](https://discourse.julialang.org/u/Luapulu)\
**Replies:** 3\
**Last updated:** [March 25, 2022, 6:05pm UTC](https://discourse.julialang.org/t/optimisations-for-loops-of-known-size-at-compile-time/78474 "2022-03-25T18:05:29Z")

</div>

Say I write a function like function func(n, ::Val{N}) where N s = 0 for i in 1:n for j in 1:N # some kind of logic here, e.g. s += i \* j end end return s end doe…

---

## [Unrolling of loops with operations on CuArrays](https://discourse.julialang.org/t/unrolling-of-loops-with-operations-on-cuarrays/70468)

<div class="topic-metadata">

**Author:** [@fedoroff](https://discourse.julialang.org/u/fedoroff)\
**Replies:** 4\
**Last updated:** [October 27, 2021, 5:10pm UTC](https://discourse.julialang.org/t/unrolling-of-loops-with-operations-on-cuarrays/70468 "2021-10-27T17:10:42Z")

</div>

I have a loop where at each iteration I do some vectorial operation over CuArray. For example using CUDA N = 4 a = ones(N) u = CUDA.zeros(1000) @. u = a\[1\] for i=2:N @. u += a\[i\] end As far as I understand, in t…

---

## [@foreach item in vector](https://discourse.julialang.org/t/foreach-item-in-vector/69024)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 2\
**Last updated:** [October 1, 2021, 5:16am UTC](https://discourse.julialang.org/t/foreach-item-in-vector/69024 "2021-10-01T05:16:00Z")

</div>

I want to run a bit of code for each item in a vector, as if I’d typed it out multiple types. Not using a function or run-time loop. How can I do that? Similar to this but with no function: foreach(1:5) do x printl…

---

## [Performance optimisation: Julia vs C++](https://discourse.julialang.org/t/performance-optimisation-julia-vs-c/59689)

<div class="topic-metadata">

**Author:** [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Replies:** 31\
**Last updated:** [April 21, 2021, 2:55pm UTC](https://discourse.julialang.org/t/performance-optimisation-julia-vs-c/59689 "2021-04-21T14:55:24Z")

</div>

Hi all! This is for the performance tweaking addicts out there :smiley: I had a conversation with a “C++ friend” today in which upon request I tried to showcase to him that Julia can be as performant as C++ (say, withi…

---

## [Unrolled loop results in Improbable @benchmark timing](https://discourse.julialang.org/t/unrolled-loop-results-in-improbable-benchmark-timing/56637)

<div class="topic-metadata">

**Author:** [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Replies:** 6\
**Last updated:** [March 7, 2021, 2:18pm UTC](https://discourse.julialang.org/t/unrolled-loop-results-in-improbable-benchmark-timing/56637 "2021-03-07T14:18:30Z")

</div>

The TLDR is why would I get improbably timings when benchmarking passing in by reference i.e. $c but get maybe reasonable timings when passing in the value i.e. ‘c’. And how much can I trust the timing passing in the va…

---

## [The birthday paradox: help to be faster than Fortran](https://discourse.julialang.org/t/the-birthday-paradox-help-to-be-faster-than-fortran/44809)

<div class="topic-metadata">

**Author:** [@profesor\_s](https://discourse.julialang.org/u/profesor_s)\
**Replies:** 16\
**Last updated:** [August 13, 2020, 7:06pm UTC](https://discourse.julialang.org/t/the-birthday-paradox-help-to-be-faster-than-fortran/44809 "2020-08-13T19:06:24Z")

</div>

Introduction I am not able to beat Fortran using Julia. This is the time spent by the algorithm using these two languages: Fortran 0m 42s Julia 4m 33s As you can see, Julia takes 6.5 times the time Fortran takes to s…

---

## [Reduce vs. foldl: performance and precision](https://discourse.julialang.org/t/reduce-vs-foldl-performance-and-precision/43231)

<div class="topic-metadata">

**Author:** [@Boo](https://discourse.julialang.org/u/Boo)\
**Replies:** 11\
**Last updated:** [July 17, 2020, 9:44pm UTC](https://discourse.julialang.org/t/reduce-vs-foldl-performance-and-precision/43231 "2020-07-17T21:44:35Z")

</div>

Hi guys, Can you explain me, please, the difference in performance and precision between reduce and foldl? julia\> using BenchmarkTools julia\> a = rand(10^7) 10000000-element Array{Float64,1}: 0.8488959437260439 0.76…

---

## [Macro to sum over short loop](https://discourse.julialang.org/t/macro-to-sum-over-short-loop/42574)

<div class="topic-metadata">

**Author:** [@weymouth](https://discourse.julialang.org/u/weymouth)\
**Replies:** 9\
**Last updated:** [July 6, 2020, 9:23am UTC](https://discourse.julialang.org/t/macro-to-sum-over-short-loop/42574 "2020-07-06T09:23:23Z")

</div>

I find myself writing code like this repeatedly function ke(I::CartesianIndex{d},u::Array{Float64}) where d s = 0. for i in 1:d s+=u\[I,i\]^2 end return 0.5s end and wanted to give Julia’s macros a try.…

---

## [Manually unroll operations with objects of tuple](https://discourse.julialang.org/t/manually-unroll-operations-with-objects-of-tuple/11604)

<div class="topic-metadata">

**Author:** [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Replies:** 21\
**Last updated:** [June 13, 2018, 12:27pm UTC](https://discourse.julialang.org/t/manually-unroll-operations-with-objects-of-tuple/11604 "2018-06-13T12:27:55Z")

</div>

I am trying to battle, overcome regressions when moving to Julia 0.7. Let’s say I have the function function next\_collision( p::AbstractParticle{T}, bt::Tuple)::Tuple{T,Int} where {T} tmin::T = T(Inf) ind::I…

---

## [Unrolled.jl – problems with "where" keyword](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715)

<div class="topic-metadata">

**Author:** [@lhupe](https://discourse.julialang.org/u/lhupe)\
**Replies:** 4\
**Last updated:** [March 17, 2018, 8:23pm UTC](https://discourse.julialang.org/t/unrolled-jl-problems-with-where-keyword/9715 "2018-03-17T20:23:45Z")

</div>

I have a function that takes an SVector of some type, i.e. function foo(vec::SVector{2,T}) where T for x in vec #do something with x end end and want to use Unrolled.jl on it. However, when I add the @u…

---

## [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…

---

## [Loop unrolling, type param to macro, generated functions](https://discourse.julialang.org/t/loop-unrolling-type-param-to-macro-generated-functions/1911)

<div class="topic-metadata">

**Author:** [@pint](https://discourse.julialang.org/u/pint)\
**Replies:** 4\
**Last updated:** [April 20, 2017, 2:05am UTC](https://discourse.julialang.org/t/loop-unrolling-type-param-to-macro-generated-functions/1911 "2017-04-20T02:05:17Z")

</div>

yeah, i don’t seem to know what my question is. below you find 3. i have a type Mod{B, A} which just encapsulates an UInt64 array. and a naive function on it: @inline limbs(b) = cld(b, 31) mul!{B, A}(r::Mod{B, A}, a:…
