> The usual way is to factor out any parts that can skew the results
> before the benchmark loop and call b.ResetTimer() just before entering
> the 'for i := 0; i < b.N; i++ {' loop.
That isn’t applicable here. It is the performing of the operation that gets progressively slower. So when comparing across implementations, you want to use a fixed number of operations, and time the overall execution time, creating a time/op output.
> I don't think it's useful. The testing package does IMO the right
Fair enough, but if you were writing a benchmark against sorting algorithms, how would you benchmark say a bubble sort against a quicksort. I guess you would insert all of the items and then ResetTimer(), and then still you would get the total sort time, not the sort time per item.
So then you need to create:
Sort1000 items
Sort10000 items
Sort100000 items
but the output it still the time it takes to run the sort, not the sort time amortized per item.
Making it much more difficult to compare different algorithms and different container sizes.