# Julia vs Fortran complaint

**URL:** <https://discourse.julialang.org/t/julia-vs-fortran-complaint/4366>\
**Category:** General Usage\
**Tags:** fortran\
**Created:** [June 20, 2017, 1:09pm UTC](https://discourse.julialang.org/t/julia-vs-fortran-complaint/4366 "2017-06-20T13:09:48Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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:** [June 20, 2017, 5:01pm UTC](https://discourse.julialang.org/t/julia-vs-fortran-complaint/4366/7 "2017-06-20T17:01:36Z")

</div>

> [@ExpandingMan](#):
>
> That said, I would agree that the statement about Fortran is probably misleading.

I know nothing about the source of the quote in question, but let me give you a real-world example in which I’ve often found that Julia code can be faster than comparable algorithms in production-quality Fortran: special-function implementations.

For example, I implemented an `erfinv` function Julia ([add inverse error functions erfinv and erfcinv by stevengj · Pull Request #2987 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/2987)), and it was about 3x faster than Matlab or SciPy’s `erfinv` function, both of which are taken from standard Fortran libraries. (This is benchmarking single-threaded vectorized calls on large arrays where the Matlab/Python overhead should be negligible.) The underlying algorithm is similar to those used in the Fortran routines (in Matlab’s case this is only a guess), because almost everyone uses the same rational-function approximations published in the 1970s.

I have found similar gains (compared to Fortran code called in SciPy) for other special functions, e.g. polygamma functions ([RFC: add complex polygamma and Hurwitz zeta functions by stevengj · Pull Request #7125 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/7125)) and exponential integrals ([exponential integral (Ei, E₁, Eₙ...) function · Issue #19 · JuliaMath/SpecialFunctions.jl · GitHub](https://github.com/JuliaMath/SpecialFunctions.jl/issues/19)).

The reason Julia can beat the Fortran code is that metaprogramming makes it easy to apply performance optimizations that are awkward in Fortran. We have metaprogramming macros (`@evalpoly`) that can easily inline polynomial evaluations, whereas the Fortran code makes function calls that loop over look-up tables of polynomial coefficients. Even greater speedups are possible for evaluating polynomials of complex arguments, where there is a fancy recurrence from Knuth that is almost impossible to use effectively without code generation. In principle, the Fortran authors _could_ have done the same inlining and gotten similar performance, but the code would have been much more painful to write by hand. (They could even have written a program to generate Fortran code, but that is even more painful.)

---

_[View the full topic](https://discourse.julialang.org/t/julia-vs-fortran-complaint/4366)._
