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


Reply via email to