Benchmarking a function with parameters

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Benchmarking a function with parameters

Uwe Fechner
Hello,

why does the following code not work (no benchmark result shown, no error message or warning):
using BenchmarkTools

function add2!(vec, result)
    """ Calculate the sum of two 3d vectors and store the result in the second parameter. """
   [result[i] =  vec[i] + result[i] for i in [1, 2, 3]]
   return nothing
end

function main()
    vec1=(1.0,2.0, 3.0)
    result=zeros(3)
    add2!(vec1, result)
    println(result)
    @benchmark add2!($vec1, $result)
end

main()


Any hints welcome!

Uwe
Reply | Threaded
Open this post in threaded view
|

Re: Benchmarking a function with parameters

Yichao Yu
On Mon, Nov 14, 2016 at 8:16 AM, Uwe Fechner <[hidden email]> wrote:

> Hello,
>
> why does the following code not work (no benchmark result shown, no error
> message or warning):
> using BenchmarkTools
>
> function add2!(vec, result)
>     """ Calculate the sum of two 3d vectors and store the result in the
> second parameter. """
>    [result[i] =  vec[i] + result[i] for i in [1, 2, 3]]
>    return nothing
> end
>
> function main()
>     vec1=(1.0,2.0, 3.0)
>     result=zeros(3)
>     add2!(vec1, result)
>     println(result)
>     @benchmark add2!($vec1, $result)
> end
>
> main()
>
> Any hints welcome!

Use @benchmark in global scope and don't use comprehension as loop.

>
> Uwe
Reply | Threaded
Open this post in threaded view
|

Re: Benchmarking a function with parameters

Uwe Fechner
This was not the problem.

The problem was, that I was using "Run" from within Juno. In that case, the result
of @benchmark is not printed.
Using:
println(@benchmark xxxx)
solved the problem.

Uwe

On Monday, November 14, 2016 at 3:12:31 PM UTC+1, Yichao Yu wrote:
On Mon, Nov 14, 2016 at 8:16 AM, Uwe Fechner <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="qQhtLL-TBgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">uwe.fec...@...> wrote:

> Hello,
>
> why does the following code not work (no benchmark result shown, no error
> message or warning):
> using BenchmarkTools
>
> function add2!(vec, result)
>     """ Calculate the sum of two 3d vectors and store the result in the
> second parameter. """
>    [result[i] =  vec[i] + result[i] for i in [1, 2, 3]]
>    return nothing
> end
>
> function main()
>     vec1=(1.0,2.0, 3.0)
>     result=zeros(3)
>     add2!(vec1, result)
>     println(result)
>     @benchmark add2!($vec1, $result)
> end
>
> main()
>
> Any hints welcome!

Use @benchmark in global scope and don't use comprehension as loop.

>
> Uwe