# How to optimise and be faster than Java?

**URL:** <https://discourse.julialang.org/t/how-to-optimise-and-be-faster-than-java/14457>\
**Category:** Performance\
**Created:** [September 3, 2018, 12:59am UTC](https://discourse.julialang.org/t/how-to-optimise-and-be-faster-than-java/14457 "2018-09-03T00:59:29Z")\
**Posts on this page:** 1\
**Showing post:** 22

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [September 3, 2018, 9:23pm UTC](https://discourse.julialang.org/t/how-to-optimise-and-be-faster-than-java/14457/22 "2018-09-03T21:23:11Z")

</div>

If I understand correctly, there isn’t much to SIMD here since each run depends on the previous run.

In julia, by convention functions mutating one of their arguments have a `!` appended to make it clear to a user that they’re modifying one of their arguments - this does not have an impact on performance though, just makes the intent clearer.

As for the benchmark, BenchmarkTools allows interpolating of outer variables with `$` (like `@btime f($x)`) - this reduces overhead of retrieving the object. `@time` in contrast includes compilation time, while @btime doesn’t. Also, you might want to use a setup for the benchmark, not to throw it off by increasing the size of the array evermore (like this: `@btime calcprojouter(x, 125) setup=(x = copy($pa))`). Be sure to check the [documentation of BenchmarkTools](https://github.com/JuliaCI/BenchmarkTools.jl/blob/master/doc/manual.md) for more information.

One idea you could still try without modifying too much is precalculating all the variables before constructing the new `Proj` and just giving those values to the constructor directly instead of creating a new `Proj` with all zeros and then mutating it.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-optimise-and-be-faster-than-java/14457)._
