Yes, function get inlined within certain limits. You can check by using 
@code_typed and looking for :call expressions (@code_typed includes the 
inlining pass).

Best,
--Tim

On Friday, May 08, 2015 09:30:57 AM Sisyphuss wrote:
> The following code is aimed to study the benefit of vectorization:
> 
> function f(a::Array{Float64,1})
>   b = Array(eltype(a),size(a))
>   n=length(a)
>   for i=1:n
>     b[i]=a[i]+1
>   end
>   return b
> end
> 
> function f(a::Float64)
>   b = a + 1
> end
> 
> 
> function main1()
>   n = 1000000
>   a = zeros(n)
>   @timeit begin
>     b = Array(eltype(a),size(a))
>     for i=1:n
>       b[i] = f(a[i])
>     end
>   end
> end
> 
> function main2()
>   n = 1000000
>   a = zeros(n)
>   @timeit b=f(a)
> end
> 
> begin
>   println("==========================")
>   main1()
>   main2()
> end
> 
> `f` is the overloaded function, which can be either vectorized or not.
> The goal is to transform every element of the vector `a` to `f(a)`, and
> store it in `b`.
> `main1` is non-vecorized, while `main2` is vectorized.
> 
> I thought that `main2` could have been more efficient than `main1`, because
> it has less function calls.
> However, according to the experiment, there is actually no performance
> difference between these two versions.
> The reason, is it because that `f()` is inlined by the compiler secretly?

Reply via email to