johnmyleswhite / Benchmarks.jl

A new benchmarking library for Julia
Other
45 stars 15 forks source link

Mutating functions re-use their arguments #30

Open mbauman opened 9 years ago

mbauman commented 9 years ago

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}:
KristofferC commented 9 years ago

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).