Skip to content

time: Ticker unpredictable behaviour #6142

@alexbrainman

Description

@alexbrainman
This program

package main

import (
    "fmt"
    "time"
)

func main() {
    timer := time.NewTicker(time.Nanosecond).C
    start := time.Now()
    for i := 0; i < 100; i++ {
        <-timer
    }
    fmt.Printf("%v\n", time.Now().Sub(start))
}

prints

- "1.56252s" on my Windows XP;
- "196.2966ms" on my Windows 7;
- "10.114019ms" on my Linux;

Which one is correct?

I would expect it to print something like "100ns". Perhaps I am wrong.

Alex

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions