Actually, if I add b.Log("time per op",float64(b.Elapsed().Microseconds())/float64(N_ORDERS*2))
I get a different value than what benchmark reports, so I am certain setting b.N is not correct. > On Jul 8, 2024, at 3:08 PM, 'Robert Engels' via golang-nuts > <golang-nuts@googlegroups.com> wrote: > > Given this code (which I know is not “correct”): > > func BenchmarkOrders(b *testing.B) { > var ob = orderBook{} > var inst = Equity{} > var ex = testExchangeClient{} > > const N_ORDERS = 1000000 > > b.ResetTimer() > > b.N = N_ORDERS > > for i:=0;i<N_ORDERS;i++ { > var o1 = LimitOrder(inst, Buy, NewDecimal("100"), NewDecimal("10")) > o1.ExchangeId = fmt.Sprint(i) > var s1 = sessionOrder{ex, o1, time.Now()} > ob.add(s1) > } > for i:=0;i<N_ORDERS;i++ { > var o1 = LimitOrder(inst, Sell, NewDecimal("100"), NewDecimal("10")) > o1.ExchangeId = "S"+fmt.Sprint(i) > var s1 = sessionOrder{ex, o1, time.Now()} > ob.add(s1) > } > > } > > Instead of setting b.N, is there a better way to get a “benchmark” for the > logical operation. > > In this case, the number of operations is 2 * N_ORDERS, so I would like to > time the entire process and output in the benchmark format the time per “op”. > > It seems to work setting b.N, but I’m sure this isn’t ideal. > > In Java JMH, you have the ability to set the “number of operations” performed > during the test - I’m looking for something similar. > > -- > 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/E5D80591-F819-4C4D-9E18-6E2438B269FB%40me.com. -- 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/63E0AA90-54AB-480F-828A-44C7376CB351%40ix.netcom.com.