# Julia programs now shown on benchmarks game website

**URL:** <https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722>\
**Category:** Community\
**Tags:** announcement\
**Created:** [November 19, 2018, 5:44pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722 "2018-11-19T17:44:02Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Juan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juan/32/7657_2.png) [@Juan](https://discourse.julialang.org/u/Juan)\
**Post date:** [November 20, 2018, 10:24am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/21 "2018-11-20T10:24:11Z")

</div>

Other languages (such as Java) have several entries on the benchmarks.  
We could also have several versions: plain Julia, Julia with some package, Optimized Julia…

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [November 20, 2018, 10:38am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/22 "2018-11-20T10:38:43Z")

</div>

I like the idea of using packages. Especially StaticArrays because it is always repeated that packages are not second grade citizens in the julia community.

---

<div class="post-metadata">

**Author:** ![igouy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igouy/32/8524_2.png) [@igouy](https://discourse.julialang.org/u/igouy)\
**Post date:** [November 22, 2018, 12:06am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/23 "2018-11-22T00:06:35Z")

</div>

Also, the vast majority who look at the source code of Julia programs on the benchmarks game website will be unfamiliar with the language — so inline comments which explain language elements particular to Julia can be very helpful.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [November 22, 2018, 2:58am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/24 "2018-11-22T02:58:16Z")

</div>

While I think it would be nice to show how easy it is to re-implement the limited functionality needed for these benchmarks without using external packages, there is precedent for using non-standard packages: Java uses `it.unimi.dsi.fastutil.longs.Long2IntOpenHashMap` in the k-nucleotide benchmark: [k-nucleotide Java program (Benchmarks Game)](https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/knucleotide-java-1.html).

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [November 22, 2018, 4:51am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/25 "2018-11-22T04:51:02Z")

</div>

By the way, BioJulia people, step up your game. Java looks beatable for k-nucleotide in terms of both readability and performance, currently way behind in the latter category. 🙂

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 22, 2018, 2:59pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/26 "2018-11-22T14:59:04Z")

</div>

This community is amazing! I cloned the repo today to try to improve some tests and I found lots of commits with lots of improvements just 3 days after! Amazing!

@kristoffer.carlsson any idea about what is left to do?

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [November 22, 2018, 4:29pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/27 "2018-11-22T16:29:02Z")

</div>

Mandelbrot, binary trees nbodies, fannkuchredux should be in relatively good shape now… If i didn’t miss anything, the rest should still leave quite a bit of room for improvement!

---

<div class="post-metadata">

**Author:** ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)\
**Post date:** [November 22, 2018, 5:29pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/28 "2018-11-22T17:29:53Z")

</div>

The bottleneck in fannkuch-redux is the function `count_flips` which makes lots of array accesses. I guess the fastest implementations use loop-unrolling techniques to utilize out-of-order execution stuff more, specifically on the loop `for k = 1:15` whose maximum number of iterations is (made) guaranteed at compile-time. I tried `@nexprs` but could not get an improvement maybe someone can take a look at there.

---

<div class="post-metadata">

**Author:** ![igouy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igouy/32/8524_2.png) [@igouy](https://discourse.julialang.org/u/igouy)\
**Post date:** [November 22, 2018, 6:02pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/29 "2018-11-22T18:02:37Z")

</div>

> [@hckr](#):
>
> loop-unrolling techniques

_fyi_ Programs with manual loop unrolling are generally not accepted — that can become a grey area when there are vector operations.

_fyi_ Programs that use fastmath are not accepted.

---

<div class="post-metadata">

**Author:** ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)\
**Post date:** [November 22, 2018, 6:41pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/30 "2018-11-22T18:41:31Z")

</div>

What is meant by manual loop unrolling, typing what each iteration should run one-by-one? Is letting a built-in macro (if any) do this kind of optimization accepted as manual loop unrolling, given that it is not done for a specific input?

Some compilers unrolls loops at compile time which I think in the same way such a macro would do and some implementations explicitly or implicitly use this feature.

---

<div class="post-metadata">

**Author:** ![igouy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/igouy/32/8524_2.png) [@igouy](https://discourse.julialang.org/u/igouy)\
**Post date:** [November 22, 2018, 7:29pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/31 "2018-11-22T19:29:43Z")

</div>

Does it show what a clever programmer could do, or does it show what the language implementation does?

---

<div class="post-metadata">

**Author:** ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)\
**Post date:** [November 22, 2018, 8:33pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/32 "2018-11-22T20:33:33Z")

</div>

It’s kind of both, isn’t it? Please take a look at [this C implementation](https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/fannkuchredux-gcc-5.html). As noted in the code, `low_index<16` is put there _violating the algorithm_ purposefully to utilize loop-unrolling (since otherwise the compiler cannot unroll a loop that can run an unknown number of times), which is, I would argue, something that a clever programmer could do. Other implementations also make this `16` trick.

I can also argue that an implementation in Julia using macros _can_ show what the language implementation does.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [November 22, 2018, 8:37pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/33 "2018-11-22T20:37:56Z")

</div>

An implementation in Julia doesn’t need that. It can just use StaticArrays which should do that.

---

<div class="post-metadata">

**Author:** ![Ronis\_BR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ronis_br/32/50999_2.png) [@Ronis\_BR](https://discourse.julialang.org/u/Ronis_BR)\
**Post date:** [November 22, 2018, 8:47pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/34 "2018-11-22T20:47:50Z")

</div>

Another point to merge StaticArrays into `stdlib` 🙂

---

<div class="post-metadata">

**Author:** ![Daniel\_Berge](https://avatars.discourse-cdn.com/v4/letter/d/eb9ed0/32.png) [@Daniel\_Berge](https://discourse.julialang.org/u/Daniel_Berge)\
**Post date:** [November 23, 2018, 3:08am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/36 "2018-11-23T03:08:25Z")

</div>

The [fastest C implementation](https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-gcc-4.html) makes use of this trick `distance = _mm_cvtps_pd(_mm_rsqrt_ps(_mm_cvtpd_ps(dsquared)))` to drop the precision to `Float32` so that the SSE instruction for approximate reciprocal square root can be used, which doesn’t exist for `Float64` until the AVX-512 extension I gather looking at Intel intrinsics guide.

---

<div class="post-metadata">

**Author:** ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)\
**Post date:** [November 23, 2018, 9:24am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/37 "2018-11-23T09:24:48Z")

</div>

This is interesting. If julia unrolls loops with StaticArrays, should not it also unroll loops like `for i = 1:16`? Perhaps, it already is unrolling.

Also, it was said we avoid using packages.

---

<div class="post-metadata">

**Author:** ![foobar\_lv2](https://avatars.discourse-cdn.com/v4/letter/f/ee59a6/32.png) [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Post date:** [November 23, 2018, 11:25am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/38 "2018-11-23T11:25:32Z")

</div>

Afaik `@fastmath` won’t emit this; see [here](https://discourse.julialang.org/t/help-speeding-up-a-test-progam-from-a-book/6383/33) if you want to use that trick. I wouldn’t call this idiomatic julia, though.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [November 23, 2018, 11:28am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/39 "2018-11-23T11:28:26Z")

</div>

> [@hckr](#):
>
> Also, it was said we avoid using packages.

Is this an official rule or the benchmarks game?

---

<div class="post-metadata">

**Author:** ![hckr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hckr/32/4836_2.png) [@hckr](https://discourse.julialang.org/u/hckr)\
**Post date:** [November 23, 2018, 11:42am UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/40 "2018-11-23T11:42:17Z")

</div>

Honestly, I have no idea, but people so far avoided it. I referred to this post above.

> [@Julia programs now shown on benchmarks game website](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/17):
>
> I think we should avoid using packages. PRs accepted. The testing and benchmarking script needs love as well. I’ll get to it in a while though if no one else beats me to it slight_smile

---

<div class="post-metadata">

**Author:** ![improbable22](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/improbable22/32/5464_2.png) [@improbable22](https://discourse.julialang.org/u/improbable22)\
**Post date:** [November 23, 2018, 12:03pm UTC](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722/41 "2018-11-23T12:03:29Z")

</div>

> [@hckr](#):
>
> If julia unrolls loops with StaticArrays, should not it also unroll loops like `for i = 1:16` ? Perhaps, it already is unrolling.

I don’t think these are unrolled by default, but Unrolled.jl has a macro which does this: `Unrolled.@unroll_loop for i=1:16 ...` will work, and in some quick tests can be faster. (It’s a one-line macro, btw, so would be trivial to include without having to call the package.)

Edit: then I read the rest of the thread, sorry! Does this count as manual or automated unrolling?

> [@igouy](#):
>
> _fyi_ Programs with manual loop unrolling are generally not accepted

[Previous page](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722.md?page=1)

[Next page](https://discourse.julialang.org/t/julia-programs-now-shown-on-benchmarks-game-website/17722.md?page=3)
