A1. There will be an overhead for each call to f, however, if f does a
significant amount of work then this overhead will likely be insignificant
since you only call f once.
A2. If you don't want to include the gc timing in your benchmark you could
completely turn off the gc for the calls to f with gc_enable(false) and
then manually run the gc after the calls.
A3. The fourth return value is the garbage collection time and the fifth is
an object which a bunch of memory allocation counters:
julia> r = @timed 1+1
(2,1.042e-6,160,0.0,Base.GC_Diff(160,0,0,4,0,0,0,0,0))
julia> fieldnames(r[5])
9-element Array{Symbol,1}:
:allocd
:malloc
:realloc
:poolalloc
:bigalloc
:freecall
:total_time
:pause
:full_sweep
On Wednesday, October 28, 2015 at 8:12:55 AM UTC+1, Greg Plowman wrote:
>
> I think I have read that passing around functions in not efficient.
> Or maybe this is just anonymous functions?
> In any case I want to run some comparison performance tests on many
> functions, so have written a general function to perform tests on functions
> passed in as arguments. See below.
>
> Q1. Is this a valid strategy? Will the passed-in functions run the same as
> when executed with an explicit call?
> Q2. In the code below, is there any benefit/downside to running gc()
> before each timing?
> Q3. I understand the first 3 return values from `@timed`, What are the
> other 2 return values? Or where can I read about these?
>
> Are there any other considerations I should be aware of?
>
>
> function PerformanceTest(f::Function, x::MyType1, y::MyType2, n::Int)
> # precompile
> @timed f(x, 1)
> @timed f(y, 1)
>
> gc() # does this help? or hinder?
> (xResult, xElapsed, xAllocated, xGC, xOther) = @timed f(x, n)
> gc()
> (yResult, yElapsed, yAllocated, yGC, yOther) = @timed f(y, n)
>
>
> # make sure we get same result
> @assert xResult == yResult
>
> @printf("%-30s %15i %15i %8s %12f %12f %8.2f %12i %12i %8.2f\n",
> f, xResult, yResult, xResult==yResult, xElapsed, yElapsed,
> yElapsed/xElapsed, xAllocated, yAllocated, yAllocated/xAllocated)
>
> yResult
> end
>
>
>