# Distance to theoretical performance limit

**URL:** https://discourse.julialang.org/t/distance-to-theoretical-performance-limit/88443
**Category:** General Usage
**Tags:** question
**Created:** [October 8, 2022, 2:36pm UTC](https://discourse.julialang.org/t/distance-to-theoretical-performance-limit/88443 "2022-10-08T14:36:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)
#### Post date: [October 8, 2022, 2:36pm UTC](https://discourse.julialang.org/t/distance-to-theoretical-performance-limit/88443/1 "2022-10-08T14:36:05Z")

</div>

Is it possible to know the distance to the theoretical performance limit for a function? The limit could be based on hardware, a fast benchmark language like C, or Julia itself.  
The reason I ask is that sometimes I wish I could have a target to aim at and know where I am. For example, if my target is to get 80% of the theoretical performance limit, then I know exactly when to stop and can better allocate my time.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [October 8, 2022, 3:20pm UTC](https://discourse.julialang.org/t/distance-to-theoretical-performance-limit/88443/2 "2022-10-08T15:20:58Z")

</div>

> [@Yifan\_Liu](#):
>
> a fast benchmark language like C

Performance is a lot more complicated than you think. Writing something in C does not automatically guarantee “optimal” performance, not even close.

Different implementations in C of the “same” algorithm (the same number of arithmetic operations) for the same function can have performance differing by orders of magnitude. See for example, [these notes on matrix-multiplication performance](https://nbviewer.org/github/mitmath/18335/blob/spring21/notes/Memory-and-Matrices.ipynb) or [these FFT benchmark results](https://www.fftw.org/speed/) (all of which are in C or Fortran and all of which have the same number of arithmetic operations within ≈25%).

The best thing you can do, in my experience, is to scour the web for other highly optimized implementations of the same (or similar) functions and benchmark them (as fairly as you can, which can take some effort).

Of course, you should also read the [Julia performance tips](https://docs.julialang.org/en/v1/manual/performance-tips/) and avoid the obvious pitfalls, like excessive allocations.
