function sumofsins1(n::Integer)
r = 0
for i in 1:n
r += sin(3.4)
end
return r
end
function sumofsins2(n::Integer)
r = 0.0
for i in 1:n
r += sin(3.4)
end
return r
end
function sumofsins3(n::Integer)
r = 0.0
const s = sin(3.4)
@simd for i in 1:n
r += s
end
return r
end
function sumofsins4(n::Integer)
r = 0.0
s = sin(3.4)
for i in 1:n
r += s
end
return r
end
sumofsins1(100_000)
sumofsins2(100_000)
sumofsins3(100_000)
sumofsins4(100_000)
@time [sumofsins1(100_000) for i in 1:100];
@time [sumofsins2(100_000) for i in 1:100];
@time [sumofsins3(100_000) for i in 1:100];
@time [sumofsins4(100_000) for i in 1:100];
elapsed time: 0.535385509 seconds (320164448 bytes allocated, 29.58% gc time)
elapsed time: 0.094625298 seconds (896 bytes allocated)
elapsed time: 0.000809309 seconds (896 bytes allocated)
elapsed time: 0.008602853 seconds (896 bytes allocated)
0.535385509/0.094625298 #@time [sumofsins2(100_000) for i in 1:100];
5.657953214583272
5X faster
0.535385509 /0.008602853 #@time [sumofsins3(100_000) for i in 1:100];
62.2334833572072
62X faster
0.535385509/0.000809309 #@time [sumofsins4(100_000) for i in 1:100];
661.5341099629437
661X faster
1 Mayıs 2015 Cuma 19:14:37 UTC-4 tarihinde Kenan KARAGÜL yazdı:
Thank you. Problem solved.
1 Mayıs 2015 Cuma 17:58:35 UTC-4 tarihinde John Myles White yazdı:
Re. perf changes: there was a regression since 2013. There's an issue
here: https://github.com/JuliaLang/julia/issues/9942
-- John
On Friday, May 1, 2015 at 12:10:37 PM UTC-7, Kenan KARAGÜL wrote:
Hi everybody,
I read an article Writing Type-Stable Code in Julia from John Myles
White in this website:
http://www.johnmyleswhite.com/notebook/2013/12/06/writing-type-stable-code-in-julia/
I have got two different results.
1) GC time is very high, John's has zero.
2) John's run time 50x faster, my run 5x faster.
Code run screenshoot in here.
Thank you very much your contributions.
Kenan