On Tue, Feb 24, 2015 at 8:03 AM, Tim Holy <[email protected]> wrote:

> Giovanni,
>
> Before you start going to that kind of effort, take a look at
>
> julia> @code_native 3+5
>         .text
> Filename: int.jl
> Source line: 12
>         push    RBP
>         mov     RBP, RSP
> Source line: 12
>         add     RDI, RSI
>         mov     RAX, RDI
>         pop     RBP
>         ret
>
> I think you're going to have a pretty hard time finding a C compiler that
> does
> better than this :-). Especially since it gets inlined at the call site.
>

Not only is a C compiler not going to do better than this, but if you take
things like adding two numbers and put them inside a C function, then you
can only call that code by a call instruction, which is significantly more
costly than actually doing the addition. There are many situations where
you get the opposite effect: by moving code into Julia from C, the code can
be inlined and specialized, making it significantly faster. In general, if
properly written Julia code is slower than C, the solution is not to
rewrite it in C, but to fix whatever is making Julia slower than C.

Reply via email to