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