# How to improve runtime with measurements.jl?

**URL:** <https://discourse.julialang.org/t/how-to-improve-runtime-with-measurements-jl/67343>\
**Category:** Performance\
**Tags:** question, measurements\
**Created:** [August 30, 2021, 11:56am UTC](https://discourse.julialang.org/t/how-to-improve-runtime-with-measurements-jl/67343 "2021-08-30T11:56:55Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [August 30, 2021, 2:13pm UTC](https://discourse.julialang.org/t/how-to-improve-runtime-with-measurements-jl/67343/7 "2021-08-30T14:13:14Z")

</div>

Yes, unfortunately that’s exepcted, I made the example of the `mean` in the issue linked above. As @Sukera pointed out, tracking correlation is hard. It’s pretty easy to write a package to propagate uncertainties super quickly ignoring correlations, this is what `Measurements.jl` did until [v0.02](https://github.com/JuliaPhysics/Measurements.jl/releases/tag/v0.0.2), but that’s also incredibly dumb and useless: almost no identies would hold, for example `x + x` and `2 * x` would give you different results.

Regarding the mean in particular, note that most of the time users want to compute the weighted mean, for which `Measurements.jl` provides a [specific function](https://juliaphysics.github.io/Measurements.jl/stable/usage/#Weighted-Average), which should have much more reasonable performance. Note that it ignores correlation, as warned in the docstring, because you’d usually apply to a sample of independent measurements anyways.

To be clear, `Measurements.jl` is slow because of an algorithmic limitation: it uses an O(n^2) algorithm to propagate uncertainties, you can understand why `mean`/`sum` are particularly bad, and get worse and worse as the size of the vector increases. There may be clever ways to reduce the complexity of the algorithm, but I never had the time to look at it. I believe the Python package [`uncertainties`](https://github.com/lebigot/uncertainties/) now has an algorithm which is O(n), or anyways better than O(n^2), but until a few years ago it was using basically the same algorithm as `Measurements.jl` (well, historically it’s the other way around). If anyone is willing to help, I’d be glad to hear from them.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-improve-runtime-with-measurements-jl/67343)._
