On Wednesday, July 7, 2021 at 8:01:54 PM UTC-4 tapi...@gmail.com wrote: > Peter's solution exhausted my memory and hang my whole computer, and I > have to restart it. >
Adjust the number of iterations (b.N), to accomodate your limited memory, For example, for 8GB use 100,000, $ go test filter_test.go -bench=Filter -benchmem -benchtime=100000x Peter > >> >> On Wednesday, July 7, 2021 at 11:29:30 AM UTC-4 tapi...@gmail.com wrote: >> >>> This doesn't work: >>> >>> func BenchmarkFilter3(b *testing.B) { >>> data := buildOrginalData() >>> data2 := make([]int, len(data)) >>> b.ResetTimer() >>> for i := 0; i < b.N; i++ { >>> b.StopTimer() >>> copy(data2, data) >>> b.StartTimer() >>> _ = Filter3(data2) >>> } >>> } >>> >>> On Wednesday, July 7, 2021 at 11:28:13 AM UTC-4 tapi...@gmail.com wrote: >>> >>>> >>>> For example, I don't want the time consumed for "copy(data2, data)" >>>> being counted. >>>> How to achieve this? >>>> >>>> func BenchmarkFilter3(b *testing.B) { >>>> data := buildOrginalData() >>>> data2 := make([]int, len(data)) >>>> b.ResetTimer() >>>> for i := 0; i < b.N; i++ { >>>> copy(data2, data) >>>> _ = Filter3(data2) >>>> } >>>> } >>>> >>> -- 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/2fc7baf5-9a9a-4cd2-98d5-a11427afa39en%40googlegroups.com.