How fast do you want the wrong answer? ;-)

On Sat, Mar 1, 2014 at 5:41 PM, Andrea Pagnani <[email protected]>wrote:

> Ok, now it makes more sense
>
> function test4()
>
>     const N=100000000
>     const delta = 2pi / N
>
>     @time begin
>         s = 0.0
>         for i=0.0:delta:2pi
>             s+= ccall((:sin,"libc"),Float64,(Float64,),i)
>         end
>         println(s)
>     end
>     @time begin
>         s = 0.0
>         for i=0.0:delta:2pi
>             s += sin(i)
>         end
>         println(s)
>     end
> end
>
> returns
> julia> test4()
> 7.00424467945944e-9
> elapsed time: 1.63142133 seconds (352 bytes allocated)
> 7.034712528404704e-9
> elapsed time: 1.912202446 seconds (352 bytes allocated)
>
>
> Which makes a lot more sense. The point is in the large numbers involved
> in the computation which, I agree, are not very frequent as argument of
> trigonometric functions. Yet good old libc performs amazingly well.
>
>
> On Saturday, March 1, 2014 10:24:55 PM UTC+1, Ivar Nesje wrote:
>>
>> I did say "big integers" in the sense "sin(x) where x > 2pi" not BigInt.
>> I should have said numbers instead of integers. I think part of the problem
>> is that openlibm might do a better job to get high precision with large
>> numbers (> 2pi) than your regular libm installation. You can also see that
>> libm and openlibm does not agree on the last 3 digits. Can you try to
>> benchmark sin of numbers less than 100?
>>
>> How did you get Julia? If downloaded a nightly distribution, you might
>> also get a less optimized version of openlibm that gives worse performance,
>> than what I am seeing.
>>
>> Ivar
>>
>> kl. 21:54:14 UTC+1 lørdag 1. mars 2014 skrev Andrea Pagnani følgende:
>>>
>>> Hi Ivar,
>>>
>>> I tried your version on my system (which I called test2.jl) and
>>> julia> test2()
>>> 1.9558914085412562
>>> elapsed time: 0.31957987 seconds (23456 bytes allocated)
>>> 1.9558914085412367
>>> elapsed time: 1.488734269 seconds (136 bytes allocated)
>>> 1.9558914085412367
>>> elapsed time: 1.549758093 seconds (136 bytes allocated)
>>>
>>> Some misconfiguration on my system?
>>>
>>> Also it does not seems to be something related to BigInt as
>>>
>>> function test3()
>>>
>>>     const N=10000000;
>>>     @time begin
>>>         s = 0.0
>>>         for i=1.0:1.0:float64(N)
>>>             s+= ccall((:sin,"libc"),Float64,(Float64,),i)
>>>         end
>>>         println(s)
>>>     end
>>>     @time begin
>>>         s = 0.0
>>>         for i=1.0:1.0:float64(N)
>>>             s += sin(i)
>>>         end
>>>         println(s)
>>>     end
>>> end
>>>
>>> Now everything is Float64, yet
>>>
>>> julia> test3()
>>> 1.9558914085412562
>>> elapsed time: 0.321183789 seconds (320 bytes allocated)
>>> 1.9558914085412367
>>> elapsed time: 1.521137678 seconds (320 bytes allocated)
>>>
>>>
>>>
>>>
>>> On Saturday, March 1, 2014 8:19:05 PM UTC+1, Ivar Nesje wrote:
>>>>
>>>> Andreas: You compare libopenlibm to the system libm
>>>>
>>>> function test1()
>>>>            const N=10000000;
>>>>            @time begin
>>>>                s = 0.0
>>>>                for i=1:float(N)
>>>>                    s+= ccall((:sin,"libc"),Float64,(Float64,),i)
>>>>                end
>>>>                println(s)
>>>>            end
>>>>            @time begin
>>>>                s = 0.0
>>>>                for i=1:float(N)
>>>>                    s+= Base.nan_dom_err(ccall((:sin,"
>>>> libopenlibm"),Float64,(Float64,),i),i)
>>>>                end
>>>>                println(s)
>>>>            end
>>>>            @time begin
>>>>                s::Float64 = 0.0
>>>>                for i=1:float(N)
>>>>                    s += sin(i)
>>>>                end
>>>>                println(s)
>>>>            end
>>>>        end
>>>> test1 (generic function with 1 method)
>>>>
>>>> does not give a significant difference between the built in `sin`
>>>> function and ccall.
>>>>
>>>> Ivar
>>>>
>>>>
>>>> kl. 19:57:03 UTC+1 lørdag 1. mars 2014 skrev Andreas Noack Jensen
>>>> følgende:
>>>>>
>>>>> But it is weird that if the definition from math.jl is added such that
>>>>>
>>>>> function test1()
>>>>>     const N=10000000;
>>>>>     @time begin
>>>>>         s = 0.0
>>>>>         for i=1:float(N)
>>>>>             s+= ccall((:sin,"libc"),Float64,(Float64,),i)
>>>>>         end
>>>>>         println(s)
>>>>>     end
>>>>>     @time begin
>>>>>         s = 0.0
>>>>>         for i=1:float(N)
>>>>>             s+= nan_dom_err(ccall((:sin,"libm"
>>>>> ),Float64,(Float64,),i),i)
>>>>>         end
>>>>>         println(s)
>>>>>     end
>>>>>     @time begin
>>>>>         s::Float64 = 0.0
>>>>>         for i=1:float(N)
>>>>>             s += sin(i)
>>>>>         end
>>>>>         println(s)
>>>>>     end
>>>>> end
>>>>>
>>>>> I get
>>>>>
>>>>> julia> Newton.test1()
>>>>>
>>>>> 1.9558914085412562
>>>>> elapsed time: 0.437409166 seconds (136 bytes allocated)
>>>>> 1.9558914085412562
>>>>> elapsed time: 0.429992684 seconds (136 bytes allocated)
>>>>> 1.9558914085412367
>>>>> elapsed time: 2.495838008 seconds (136 bytes allocated)
>>>>>
>>>>>
>>>>>
>>>>> 2014-03-01 19:50 GMT+01:00 Ivar Nesje <[email protected]>:
>>>>> >
>>>>> > Why do you care for the performance of sin of big integers? I got
>>>>> about 2 time difference with your test function, but when I did the test
>>>>> with 1.2 as the constant value to take sin of and got.
>>>>> >
>>>>> > julia> function test1()
>>>>> >            const N=10000000;
>>>>> >            @time begin
>>>>> >                s = 0.0
>>>>> >                for i=1:N
>>>>> >                    s+= ccall((:sin,"libc"),Float64,(Float64,),1.2)
>>>>> >                end
>>>>> >                println(s)
>>>>> >            end
>>>>> >            @time begin
>>>>> >                s = 0.0
>>>>> >                for i=1:N
>>>>> >                    s += sin(1.2)
>>>>> >                end
>>>>> >                println(s)
>>>>> >            end
>>>>> >        end
>>>>> > test1 (generic function with 1 method)
>>>>> >
>>>>> > julia> test1()
>>>>> > 9.320390858253522e6
>>>>> > elapsed time: 1.071002334 seconds (168 bytes allocated)
>>>>> > 9.320390858253522e6
>>>>> > elapsed time: 0.930658493 seconds (168 bytes allocated)
>>>>> >
>>>>> >
>>>>> > It would be expected that the native sin function in Julia would be
>>>>> slower than ccall to libc, because we check the return value to raise an
>>>>> exception (instead of a NaN value).
>>>>> >
>>>>> > We also use openlibm for our math functions, and the performance of
>>>>> that might be different from the libm on your system.
>>>>> >
>>>>> > Ivar
>>>>> >
>>>>> > kl. 18:53:39 UTC+1 lørdag 1. mars 2014 skrev Andrea Pagnani følgende:
>>>>> >>
>>>>> >> Dear all,
>>>>> >>
>>>>> >> julia's trigonometric functions seem to be almost 5 time slower
>>>>> than their libc counterpart (at least on my MacBook Pro OS X 10.9.2):
>>>>> >>
>>>>> >> function test1()
>>>>> >>
>>>>> >>     const N=10000000;
>>>>> >>     @time begin
>>>>> >>         s = 0.0
>>>>> >>         for i=1:N
>>>>> >>             s+= ccall((:sin,"libc"),Float64,(Float64,),i)
>>>>> >>         end
>>>>> >>         println(s)
>>>>> >>     end
>>>>> >>     @time begin
>>>>> >>         s = 0.0
>>>>> >>         for i=1:N
>>>>> >>             s += sin(i)
>>>>> >>         end
>>>>> >>         println(s)
>>>>> >>     end
>>>>> >> end
>>>>> >>
>>>>> >>
>>>>> >> If you run this simple code you obtain
>>>>> >>
>>>>> >> julia> test1()
>>>>> >> 1.9558914085412562
>>>>> >> elapsed time: 0.275374895 seconds (88 bytes allocated)
>>>>> >> 1.9558914085412367
>>>>> >> elapsed time: 1.567108143 seconds (88 bytes allocated)
>>>>> >> 1.9558914085412367
>>>>> >>
>>>>> >> The same behaviour is obtained with other trigonometric functions
>>>>> >> Is this something to be expected?
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Med venlig hilsen
>>>>>
>>>>> Andreas Noack Jensen
>>>>>
>>>>

Reply via email to