-
Notifications
You must be signed in to change notification settings - Fork 17.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
time: UnixNano() is rounded to microsecond #27301
Comments
Noticed same behaviour today, looks like introduced here https://go-review.googlesource.com/c/go/+/110655 |
https://go-review.googlesource.com/c/go/+/110655 introduced getting time by calling
|
Well, we use
You'll get nanosecond resolution. So I'm going to close this as unfortunate. Nanosecond resolution is available for timing things within a process. You'll only get microsecond resolution when timing things across processes or machines. That seems not so bad. |
A slightly more complete example of getting, roughly, "now" in nanoseconds: package main
import (
"fmt"
"time"
)
func main() {
start := time.Now()
for i := 0; i < 4; i++ {
diff := time.Since(start)
fmt.Println(start.Add(diff).UnixNano()) // 🤢
time.Sleep(time.Millisecond)
}
}
// Output like:
// 1535499310436503279
// 1535499310437885044
// 1535499310439308031
// 1535499310440693511 |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?1.11
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
NOT microsecond rounded every time
What did you see instead?
microsecond rounded every time
The text was updated successfully, but these errors were encountered: