It would be helpful to give more information as to why you say "This doesn't work"?But, I'm guessing that you are not seeing a decline in times when using StartTimer/StopTimer.It is likely that is because the copy function is fast, and frequent calls to StartTimer/StopTimer involve some error/overhead. So they are counteracting each other. Note that the documentation says the StopTimer can be used for "complex initialization", and I am guessing that a 1k copy does not count as complex. If you change the buffer size from 1024 to 1024*16 then you will see that the StartTimer/StopTimer version is in fact faster.PeterGo's solution works fine, as does bench marking a larger buffer. But if your goal is to compare BenchmarkFilter3 and BenchmarkFilter4, then you could reasonably just ignore the the overhead, since it will be the same for both functions.
On Wednesday, July 7, 2021 at 12:32:38 PM UTC-4 jake...@gmail.com wrote:It would be helpful to give more information as to why you say "This doesn't work"?But, I'm guessing that you are not seeing a decline in times when using StartTimer/StopTimer.It is likely that is because the copy function is fast, and frequent calls to StartTimer/StopTimer involve some error/overhead. So they are counteracting each other. Note that the documentation says the StopTimer can be used for "complex initialization", and I am guessing that a 1k copy does not count as complex. If you change the buffer size from 1024 to 1024*16 then you will see that the StartTimer/StopTimer version is in fact faster.PeterGo's solution works fine, as does bench marking a larger buffer. But if your goal is to compare BenchmarkFilter3 and BenchmarkFilter4, then you could reasonably just ignore the the overhead, since it will be the same for both functions.The StartTimer/StopTimer in my example doesn't work for the "go test" command hang there for ever.
Peter's solution exhausted my memory and hang my whole computer, and I have to restart it.