# Making @benchmark outputs statistically meaningful, and actionable

**URL:** <https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256>\
**Category:** Profiling\
**Tags:** benchmark, benchmarktools\
**Created:** [September 26, 2023, 11:38am UTC](https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256 "2023-09-26T11:38:25Z")\
**Posts on this page:** 4\
**Page:** 7

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 1, 2023, 7:51pm UTC](https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256/121 "2023-10-01T19:51:10Z")

</div>

AFAIK PGO for Julia user code is a relevant topic. Were Julia to gain profile-guided recompilation as an option for Julia packages, as mentioned [here](https://discourse.julialang.org/t/has-pgo-for-re-compiling-methods-been-considered/97426), `BenchmarkTools` could presumably stay simple, because LLVM would take care of the complexity. That is, `BenchmarkTools` would just need to recompile with PGO, which should (when enough PGO-based optimizations are implemented) ensure that some of the issues mentioned here don’t matter.

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [October 1, 2023, 8:17pm UTC](https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256/122 "2023-10-01T20:17:41Z")

</div>

> [@user664303](#):
>
> There is basically nothing else going on. Just for you, I’ve started Julia with:
> 
> ```julia
> sudo nice -n -20 julia
> 
> ```
> 
> This sets the Julia process to the highest priority possible. Given these two things, the idea that something would interrupt the Julia process seems remote.

No, `nice` doesn’t cut it. To prevent interruption you’d need to run Julia with a real time priority, perhaps using `chrt`. Also you’d probably need to fiddle with kernel options for real time scheduling (by default Linux reserves some time for non-realtime processes, so you’d need to turn that off), and possibly with other scheduler options. See this, for a start: [Real-Time group scheduling — The Linux Kernel documentation](https://docs.kernel.org/scheduler/sched-rt-group.html)

You might also want to fiddle with kernel and/or CPU options that control the powersaving/performance trade offs and similar.

You might also want to reserve some cores for Julia.

If you go down this route, make sure not to damage your system. EDIT: if you forbid the kernel from preempting your process, I think you need to make that process yield to the kernel on its own volition, by doing explicit sleeps every so often. Not sure if this is doable without modifying `BenchmarkTools`, and maybe even the Julia runtime.

There are tons of other things that can affect performance. For example, plugging in a laptop’s charger, so that it’d have more power available, usually improves performance compared to running merely off battery power.

---

<div class="post-metadata">

**Author:** ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)\
**Post date:** [October 1, 2023, 8:33pm UTC](https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256/123 "2023-10-01T20:33:24Z")

</div>

> [@nsajko](#):
>
> For example, plugging in a laptop’s charger, so that it’d have more power available, usually improves performance compared to running merely off battery power.

I’m aware of this one. All my tests were done with my laptop plugged in.

---

<div class="post-metadata">

**Author:** ![user664303](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/user664303/32/37843_2.png) [@user664303](https://discourse.julialang.org/u/user664303)\
**Post date:** [November 15, 2023, 1:01pm UTC](https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256/124 "2023-11-15T13:01:44Z")

</div>

A couple of updates to this thread:

1. Somebody replied to [my Stabilizer issue](https://github.com/Dead2/stabilizer/issues/32) saying

> “there are problems with stabilizer that I don’t know how to solve with reasonable effort. Check other open issues before proceeding further ahead.”

This suggests that Stabilizer may not be a good solution to randomizing memory layout.

1. Prof. Berger replied to my email, and [shared this document on design of a benchmark suite](https://github.com/bytecodealliance/rfcs/blob/main/accepted/benchmark-suite.md) for evaulating a couple of web stack libraries. It’s not particularly relevant or helpful for us, except that it lists the following requirements for mitigating measurement bias caused by memory layout:  
a) Shuffling allocator  
b) Stack padding  
c) Shuffling linker  
d) Randomizing environment variables

There were also some links to some helpful academic papers at the bottom of the page.

I don’t know enough about Julia’s compilation process to know where and how these randomizations could be implemented.

[Previous page](https://discourse.julialang.org/t/making-benchmark-outputs-statistically-meaningful-and-actionable/104256.md?page=6)
