I want to print N lines per second.
for i := 0; i < N; i++ {
fmt.Println(getLogs())
time.Sleep(1000000000/N * time.Nanosecond)
}
But it seems fmt.Println() and getLogs() will also consume time. So actually it will cost me more than 1s to print N lines.
Say getLogs() and fmt.Println() will both cost 1 ms. And I want to print 1 million lines per second. Therefore, to print 1 line will cost 1 ms to getLogs(), 1 ms to print, and 1 ms to sleep... It will cost me 3s to print N lines.
Any better solutions to achieve this more accurately?