I'm kind of curious why LLVM is leaving the loop in there. Anyone happen to
know?


On Sun, Mar 23, 2014 at 1:24 AM, John Myles White
<[email protected]>wrote:

> To follow up on this point — for small loops, the compiler will completely
> remove the loop:
>
> function f()
> res = 0
> for i in 1:10
> res += i
>  end
> return res
> end
>
> code_llvm(f, ())
>
> ->
>
> define i64 @julia_f15221() {
> pass2:
>   ret i64 55, !dbg !375
> }
>
>  — John
>
> On Mar 22, 2014, at 10:19 PM, Jason Merrill <[email protected]> wrote:
>
> The machine code generated by g is kind of amusing. I'm going to define g3
> slightly differently to avoid some confusion:
>
> julia> function g3()
>            x = 0
>            for n = 1:100000000 x += 3 end
>            return x
>        end
> g3 (generic function with 1 method)
>
> julia> code_native(g3, ())
>     .section    __TEXT,__text,regular,pure_instructions
> Filename: none
> Source line: 3
>     push    RBP
>     mov    RBP, RSP
>     mov    EAX, 100000000
> Source line: 3
>     dec    RAX
>     jne    -9
>     mov    EAX, 300000000
> Source line: 4
>     pop    RBP
>     ret
>
> I'm not a machine code whiz, but if I'm reading this correctly, Julia is
> precomputing the answer (I thought it might), but then running an empty
> loop 100000000 anyway before returning the precomputed answer.
>
> Given that compilers do this type of thing, you might want to reconsider
> drawing any conclusions at all from timing a loop that's as simple as the
> one you've written.
>
> On Saturday, March 22, 2014 9:18:42 PM UTC-7, Jason Merrill wrote:
>>
>> This is not a small nit that John is picking:
>>
>> julia> @elapsed begin
>>          x = 0
>>          for n = 1:100000000
>>            x += 1
>>          end
>>          x
>>        end
>> 7.333491931
>>
>> julia> function g()
>>            x = 0
>>            for n = 1:100000000 x += 1 end
>>            return x
>>        end
>> g (generic function with 1 method)
>>
>> julia> @elapsed g()
>> 0.047755206
>>
>> The second version makes you wonder what on earth PyPy is doing for a
>> whole second ;-)
>>
>> On Saturday, March 22, 2014 2:18:22 PM UTC-7, John Myles White wrote:
>>>
>>> Is this in the global scope?
>>>
>>>  — John
>>>
>>> On Mar 22, 2014, at 2:16 PM, Bob Cowdery <[email protected]> wrote:
>>>
>>> > I know this is hardly a scientific test but I'm curious why Julia is 5
>>> times slower than PyPy on an almost empty loop.
>>> >
>>> > julia> x=0
>>> > julia> for n = 1:100000000
>>> >        x += 1
>>> >        end
>>> >
>>> > Time 5s
>>> >
>>> > PyPy  takes 1s and Python takes 19s for the equivalent loop. All
>>> executed from the command line.
>>> >
>>> > Bob
>>>
>>>
>

Reply via email to