monotime

package module
v0.0.0-...-30dba43 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 2 Imported by: 37

README

monotime GoDoc Travis

This tiny Go package is a standalone and slightly enhanced version of goarista/monotime.

It provides monotime.Now() function, which returns current time from monotonic clock source. It's implemented using unexported runtime.nanotime() function from Go runtime. It works on all platforms.

Not needed for Go 1.9+

Starting from Go 1.9, the standard time package transparently uses Monotonic Clocks when necessary, so this package is no longer relevant.

This repository has been archived and is no longer maintained.

Synopsis

In Go versions before 1.9, time.Now() function from standard library returns real time (CLOCK_REALTIME in POSIX) which can jump forwards and backwards as the system time is changed.

For time measurements, monotonic time (CLOCK_MONOTONIC or CLOCK_MONOTONIC_RAW on Linux) is often preferred, which is strictly increasing, without (notable) jumps.

Documentation

See GoDoc.

Usage example

package main

import (
    "fmt"
    "time"

    "github.com/gavv/monotime"
)

func main() {
    var start, elapsed time.Duration

    start = monotime.Now()
    time.Sleep(time.Millisecond)
    elapsed = monotime.Since(start)

    fmt.Println(elapsed)
    // Prints: 1.062759ms
}

Similar packages

License

Apache 2.0

Documentation

Overview

Package monotime provides functions to access monotonic clock source.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Now

func Now() time.Duration

Now returns the current time in nanoseconds from a monotonic clock.

The time returned is based on some arbitrary platform-specific point in the past. The time returned is guaranteed to increase monotonically without notable jumps, unlike time.Now() from the Go standard library, which may jump forward or backward significantly due to system time changes or leap seconds.

It's implemented using runtime.nanotime(), which uses CLOCK_MONOTONIC on Linux. Note that unlike CLOCK_MONOTONIC_RAW, CLOCK_MONOTONIC is affected by time changes. However, time changes never cause clock jumps; instead, clock frequency is adjusted slowly.

func Since

func Since(t time.Duration) time.Duration

Since returns the time elapsed since t, obtained previously using Now.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL