Benchmarks.jl icon indicating copy to clipboard operation
Benchmarks.jl copied to clipboard

Mutating functions re-use their arguments

Open mbauman opened this issue 10 years ago • 1 comments

This is particularly strange for things like push!:

julia> v = Int[]
0-element Array{Int64,1}

julia> @benchmark push!(v,1)
================ Benchmark Results ========================
     Time per evaluation: 15.20 ns [15.01 ns, 15.40 ns]
Proportion of time in GC: 0.00% [0.00%, 0.00%]
        Memory allocated: 0.00 bytes
   Number of allocations: 0 allocations
       Number of samples: 10301
   Number of evaluations: 36687001
         R² of OLS model: 0.954
 Time spent benchmarking: 0.74 s


julia> v
36687002-element Array{Int64,1}:

mbauman avatar Oct 07 '15 19:10 mbauman

FWIW, there was a recent talk at CppCon by Chandler Carruth where he demonstrates some interesting micro benchmarks problems precisely by benchmarking push_back, see https://youtu.be/nXaxk27zwlk?t=924

The way he does it is he measures the time to create the vector and push into it and to only create the vector, separately, then takes the difference between the two.

The talk is quite interesting because he talks about some of the problems that this package also deals with (inlining of functions, defeating the optimizer etc).

KristofferC avatar Oct 07 '15 19:10 KristofferC