🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

github.com/gavv/monotime

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/gavv/monotime

v0.0.0-20190418164738-30dba4353424
Source
Go
Version published
Created
Source

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

FAQs

Package last updated on 18 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts