> 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. > On Jul 8, 2024, at 3:51 PM, Jan Mercl <0xj...@gmail.com> wrote: > > On Mon, Jul 8, 2024 at 10:36 PM Robert Engels <rob...@me.com> wrote: > >> Is there anyway to do what I want? > > 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. > >> If not, maybe a useful addition, see >> https://javadoc.io/doc/org.openjdk.jmh/jmh-core/latest/org/openjdk/jmh/annotations/OperationsPerInvocation.html >> for a similar Java api. > > I don't think it's useful. The testing package does IMO the right > thing. The task of the benchmark loop is to always do the same > unit/amount of work b.N times. Only then it all together makes sense > and can produce meaningful data about the unit/amount. It follows that > measuring O(b.N^2) algorithms cannot work very well. But you can often > measure b.N times a O(K^2) work using a constant K. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/FABCC32C-1918-4E60-87A2-AB4F8E0E7CAD%40me.com.