In [1]:
using DataFrames
function timeIt(fs::Array{Function}, k)
    nf=length(fs)
    #Initialize and output checks
    outs_init=[f() for f in fs]
    times=fill(0.0, 3, k, nf)
    for (i,f) in enumerate(fs)
        for j=1:k
            t=@timed f()
            times[:,j,i]=[t[2:end]...]
        end
    end
    out_last=[f() for f in fs]
    out_same=nf>1 ? [NaN; [out_last[i]==out_last[1] for i=2:nf]] : [true]
    out_consistent=[x==y for (x,y) in zip(outs_init, out_last)]
    times[2,:,:]/=1e6

    averages=mean(times,2)
    averages_min=minimum(averages,3)
    medians=median(times,2)
    medians_min=minimum(medians,3)
    e_notation(x)=@sprintf("%.02e", x)
    results=DataFrame(
        Function=map(string, fs),
        Consistent=out_consistent,
        Same=out_same,
        Avg_t=map(e_notation, vec(averages[1,:,:])),
        Avg_t_X= nf>1 ? map(e_notation, vec(averages[1,:,:])./vec(averages_min[1,:,:])) : [NaN],
        Med_t=map(e_notation, vec(medians[1,:,:])),
        Med_t_X= nf>1 ? map(e_notation, vec(medians[1,:,:])./vec(medians_min[1,:,:])) : [NaN],
        Avg_mem=map(e_notation, vec(averages[2,:,:])),
        Avg_mem_X= nf>1 ? map(e_notation, vec(averages[2,:,:])./vec(averages_min[2,:,:])) : [NaN],
        Med_mem=map(e_notation, vec(medians[2,:,:])),
        Med_mem_X= nf>1 ? map(e_notation, vec(medians[2,:,:])./vec(medians_min[2,:,:])) : [NaN]
    )
    return results
end
timeIt(f::Function, k)=timeIt([f], k)
timeIt([()->(), ()->1],5);
In [ ]:
A=randn(100,100)
f1()=randn(100,100)
f2()=randn(200,200)
f3()=A*1
f4()=2.0*A*0.5
timeIt([f1, f2, f3, f4],100)
Out[ ]:
FunctionConsistentSameAvg_tAvg_t_XMed_tMed_t_XAvg_memAvg_mem_XMed_memMed_mem_X
1f1falseNaN1.02e-046.34e+001.01e-048.87e+008.00e-021.00e+008.00e-021.00e+00
2f2falsefalse3.84e-042.40e+013.80e-043.35e+013.20e-014.00e+003.20e-014.00e+00
3f3truefalse1.60e-051.00e+001.13e-051.00e+008.00e-021.00e+008.00e-021.00e+00
4f4truefalse2.74e-051.71e+002.21e-051.95e+001.60e-012.00e+001.60e-012.00e+00