Skip to content
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: Nanosecond() on Windows return identical value in loop execution #28084

Closed
we-zhang opened this issue Oct 8, 2018 · 5 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@we-zhang
Copy link

we-zhang commented Oct 8, 2018

What version of Go are you using (go version)?

1.9.4

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

Build Windows executable on Mac, and run the executable on Windows

What did you do?

func main() {

	t := os.Getenv("IN_TIMES")
	count, err := strconv.Atoi(t)
	if err != nil {
		count = 10
	}

	for i := 0; i < count; i++ {
		fmt.Printf("current time nano: %s \n", strconv.Itoa(time.Now().Nanosecond()))
	}
}

What did you expect to see?

Except to see different output nasosecond value

What did you see instead?

See identical output:

current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500
current time nano: 9116500

@we-zhang we-zhang changed the title time: Nanosecond() on Windows return same value in loop execution time: Nanosecond() on Windows return identical value in loop execution Oct 8, 2018
@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 9, 2018
@agnivade agnivade added this to the Go1.12 milestone Oct 9, 2018
@kardianos
Copy link
Contributor

You may want to try it with go1.11, but by default the platform timer is lower resolution then other system.

I can't remember if Alex was successful in integrating the high res timers or if that turned out to be too expensive.

@mattn
Copy link
Member

mattn commented Oct 9, 2018

I tried with IN_TIMES=100

current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 860335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 861335000 
current time nano: 862335000 

The resolution of timer on Windows is not good. And Go's runtime adjusts this resolution internally so you probably can not get a fine resolution. (AFAIK)

@agnivade
Copy link
Contributor

agnivade commented Oct 9, 2018

Seems like that. @alexbrainman for further comments.

We can close this out if this is WAI.

@alexbrainman
Copy link
Member

Yes, what everyone else said. Windows clock does not provides resolution in nanoseconds.

Alex

@agnivade
Copy link
Contributor

agnivade commented Oct 9, 2018

Seems like WAI. Closing.

@agnivade agnivade closed this as completed Oct 9, 2018
@golang golang locked and limited conversation to collaborators Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

6 participants